SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Enthusiast steveorg's Avatar
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Domain forwarding question

    I'm changing a company name and need to switch from domain1.com to domain2.com. All of the URLs on domain1 have a corresponding URL on domain2. Both domains are on cPanel hosting.

    I want to forward all www.domain1.com URLs to the equivalent www.domain2.com URL. For example www.domain1.com/faqs should forward to www.domain2.com/faqs. Parameters in the URL (ie ?var=xxx&var2=yyy) should also forward.

    I do not want to forward other subdomains. The MX records for email are handled by a different server and should not forward. It may be worth noting that the .htaccess file is used to force www (ie domain1.com/faqs forwards to www.domain2.com/faqs) and that DNS management is handled through the Cloudflare CDN service.

    What would be the best way to set-up the forwarding? I'd prefer to eventually close the domain1 cPanel account, but I also do not mind keeping it since it costs me nothing to do so.

    Thanks,
    Steve
    ---------------

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,616
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Use the 3rd one down http://www.websitecodetutorials.com/...new-domain.php

    // 1:1 redirect - all old domain files will be redirected to new domain file locations
    RewriteRule .* http://www.newdomain.com/$1 [R=301,L]

  3. #3
    SitePoint Enthusiast steveorg's Avatar
    Join Date
    Oct 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Use the 3rd one down http://www.websitecodetutorials.com/...new-domain.php

    // 1:1 redirect - all old domain files will be redirected to new domain file locations
    RewriteRule .* http://www.newdomain.com/$1 [R=301,L]
    Thanks for the link. Unfortunately they made a mistake and repeated the solution for the first condition, which is "redirect all files from old domain to root of new domain".

    I did more searching and came up with this excellent solution. It has both a www and non-www example. Since the new site also redirects non-www to www, I was able to use the www version of the code on the old site.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Use the 3rd one down http://www.websitecodetutorials.com/...new-domain.php

    // 1:1 redirect - all old domain files will be redirected to new domain file locations
    RewriteRule .* http://www.newdomain.com/$1 [R=301,L]
    Don't forget parentheses.

    RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

    Quote Originally Posted by steveorg
    I want to forward all www.domain1.com URLs to the equivalent www.domain2.com URL.
    Apache has a Redirect directive for exactly this kind of situation.

    # htaccess on domain1.com
    Redirect permanent / http://www.domain2.com/
    "First make it work. Then make it better."

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,616
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    It's not repeated look closer

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,616
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    I actually had the parentathese in there originally and was told by someone I believed (don't remember) that they were not nessesarry if I was only doing yada yada

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    I actually had the parentathese in there originally and was told by someone I believed (don't remember) that they were not nessesarry if I was only doing yada yada
    In the first two examples on your site, the parentheses are indeed not necessary, because you're not using any captured value in the replacement. But in your third example, the replacement uses $1, which will be blank unless you use parentheses to capture the path.
    "First make it work. Then make it better."

  8. #8
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,616
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    In the first two examples on your site, the parentheses are indeed not necessary, because you're not using any captured value in the replacement. But in your third example, the replacement uses $1, which will be blank unless you use parentheses to capture the path.
    Ahh ok. Only the third? Not the 4th?

  9. #9
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Ahh ok. Only the third? Not the 4th?
    The fourth is a redirect, not a rewrite rule. It doesn't even take regular expressions.
    "First make it work. Then make it better."

  10. #10
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,616
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    The fourth is a redirect, not a rewrite rule. It doesn't even take regular expressions.
    Lol sorry I should of looked first I guess before asking.


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
  •