Domanda

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?

È stato utile?

Soluzione

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]

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top