Proper 301 Syntax for Redirecting Pages from Multiple Domains

Hi,
When we create new sites for clients, we always add 301 redirects for their old pages so they don’t lose any SEO ‘juice’ or get errors. Sometimes we are using the same domain for the new site, sometimes it’s a new domain. When a new domain is used, we park their old domain on the cPanel account so we have access to it and can do redirects locally in our .htaccess file.

All sites are WordPress and hosted on our dedicate server running WHM/cPanel.

We typically add redirects using the following syntax to work with our WordPress sites when the domain is not changing:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^about\.html$ http://www.domain.com/about/ [R=301,L]
RewriteRule ^parents\.html$ http://www.domain.com/parents/ [R=301,L]
…etc

I believe when the domain is going to be new, however, we can get away with the more standard:

redirect 301 /about.html/ http://www.domain.com/about/


1) What would be the proper syntax if we needed to redirect old pages from TWO different domains/sites to one new site, especially if there was a possibility they may have duplicate old page URLs?

We are combining 2 current sites using unique domains into 1 new ‘combined’ site using a new domain. Want to redirect the pages from their old sites (which ‘may’ have identical page URLs on occasion) to the proper new pages on the new site, which would be different for each. Both of the old domains will be parked on this new account with their registrars pointing properly, so we do have access to redirect these domains.

Thanks! Let me know if anything is not clear.

It depends on whether each domain will get its own virtual host or not. If each domain gets its own virtual host, and therefore each domain gets its own htaccess, then you can use Redirect. Or, if each domain – both old and new – are using the same virtual host, and therefore sharing the same htaccess, then your best bet is to use RewriteRule, because that lets you use RewriteCond to restrict the redirects to only certain domains.

Hi Jeff, thanks for the reply!

These will be on a single virtual host (using the same cPanel account), so they both use the same root .htaccess file.

Can you give any examples of the proper syntax for me, though? I’m just not too familiar with the language, and the examples I’ve used before (see above) don’t ever specify the ‘old’ domain, just the new.

You can use something like ‘oldA.com’, ‘oldB.com’, ‘newAB.com’. And remember that some of the old pages on the two domains may have the same names (i.e., ‘http://oldA.com/aboutus.html’ & ‘http://oldB.com/aboutus.html’) but need to be redirected to different pages on the new domain.

Thank you! I appreciate it.

Your original post already has the proper syntax.

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^about\.html$ http://www.domain.com/about/ [R=301,L]
RewriteRule ^parents\.html$ http://www.domain.com/parents/ [R=301,L]

OK. Maybe I was over-thinking it. Since that example was for the same old/new domain, I hadn’t really paid as much attention to the RewriteCond lines.

So would this be correct:

RewriteCond %{HTTP_HOST} ^oldA.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldA.com$
RewriteRule ^about\.html$ http://www.newAB.com/about/ [R=301,L]
RewriteRule ^parents\.html$ http://www.newAB.com/parents/ [R=301,L]

RewriteCond %{HTTP_HOST} ^oldB.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldB.com$
RewriteRule ^about\.html$ http://www.newAB.com/about-2/ [R=301,L]
RewriteRule ^parents\.html$ http://www.newAB.com/parents-2/ [R=301,L]

Let me know id I’m missing anything.

Thanks again!

Kenny

Looks right to me.

Hi,
We actually are going to do the redirects on the existing accounts for now since they are on the same server and we can’t park live domains on our new site until the existing ones are deleted.

So for these, we have to use the simpler ‘Redirect 301 /oldpage/ http://www.newab.com/newpage’ format.

But if we setup specific redirects for all/most of the subpages on the site, how do we get the root home page to redirect properly as well?

When I use ‘Redirect 301 / http://www.newab.com/’ it redirects all subpages to the same corresponding subpages on the new site, instead of using my specific redirects I’ve added.

  • How can we get both the home page AND different end subpages to redirect together properly?

Thanks. I’m sure it’s simple…

Kenny

You may need to use RedirectMatch is that case.

[FONT=Courier New]RedirectMatch 301 [COLOR=“#FF0000”][1]/$ http://www.newab.com/[/FONT]


  1. /COLOR ↩︎

Great, thanks.

Now, would I add this in addition to the standard ‘Redirect 301 /oldpage/ http://www.newAB.com/newpage’ lines that I currently have for all the subpages?

Or would I need to use RedirectMatch for all redirects (i.e., you can’t mix & match different methods)?

Thanks!

You can mix and match. All your other redirects should be able to stay as they are.