Question

I am moving site and I want to do a 301 redirect on all but some of the URLs,

Like this:

oldsite.com/* -> www.newsite.com

oldsite.com/specific/article/to/redirect -> www.newsite.com/fancy/blah

So there are a few things I want to redirect to specific pages but all the rest should just goto root, how can this be done in .htaccess?

Was it helpful?

Solution

Add the following to the .htaccess file in the root directory of your old site.

#place your specific redirects first 
Redirect 301 /specific/article/to/redirect http://www.newsite.com/fancy/blah

RewriteEngine on

#then your general redirect all to new site last
RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [L,R=301]

OTHER TIPS

There's RedirectMatch if you've got only one URL that needs to be exempted.

RedirectMatch permanent !/specific/article/to/redirect http://www.newsite.com

for multiple URLs, you'd probably be better off with mod_rewrite and an external rewritemap that lists the urls to be exempted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top