0

Is it possible at the same time to

  • redirect 301 multiple URLs/pages from old to new
  • redirect 301 all remain old pages to new homepage
  • redirect 301 both www/without of old homepage to new homepage
  • exclude one URL

URLs don't match (meaning each old site URL is redirected to a different URL at the new site.

  • Are the old and new sites hosted in the same webspace, or are they entirely separate? – MrWhite Jul 11 '16 at 15:20
1

Maybe try something like this:

RewriteCond %{HTTP_HOST} !^oldsite.com$
RewriteRule ^/?unchanged/url - [L,QSA]

RewriteCond %{HTTP_HOST} !^(www\.)?newsite.com$
RewriteRule ^(/?specific/page) http://newsite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(www\.)?newsite.com$
RewriteRule ^ http://newsite.com/ [R=301,L]

The order is the important part. First, handle the URL which you don't want to apply the rules to. The [L] flag should stop processing further rules. Then, handle your other specific URLs. After that, redirect the other URLs.

  • 1
    Since this is intended to be in .htaccess, the RewriteRule pattern shouldn't start with a slash. In the first RewriteRule, you can simply use a - (hyphen) for the substitution to indicate no change (is the HTTP_HOST check required here? Or should it be reversed? I assume it is intended to go on the old site?). – MrWhite Jul 11 '16 at 15:30
  • Thanks. Those are some great tips. I was assuming that for the unchanged URL, I would need a HTTP_HOST because I couldn't specify that in the rule itself, and perhaps he only wants the one URL unchanged. I suppose that I'm also assuming that both are sharing the same document root. – DKing Jul 11 '16 at 15:43

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.