SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jethrodesign View Post
    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?
    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.
    "First make it work. Then make it better."

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jethrodesign View Post
    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.
    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]
    "First make it work. Then make it better."

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Looks right to me.
    "First make it work. Then make it better."

  7. #7
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    You may need to use RedirectMatch is that case.

    RedirectMatch 301 ^/$ http://www.newab.com/
    "First make it work. Then make it better."

  9. #9
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  10. #10
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    You can mix and match. All your other redirects should be able to stay as they are.
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •