3

I believe the following code will redirect my old domain to my new domain keeping the same URL paths.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk 
RewriteRule (.*) https://www.newdomain.co.uk/$1 [R=301,L]

However, I also have some URLS from my old site that don't exist on my new site, so they would return a 404 with the rule above.

How do I redirect these to an alternative URL path?

2

You simply need to redirect these specific URLs before your catch-all redirect above. For example:

RewriteRule ^old-url-does-not-exist$ /new-url-that-does-exist [R=301,L]

Just to note... in .htaccess there is no slash prefix on the source URL pattern, ie. the regex ^old-url-does-not-exist$ matches the URL /old-url-does-not-exist. Whereas there is a slash prefix on the destination URL. That's just RewriteRule syntax.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.