steveorg — 2013-04-22T10:33:33-04:00 — #1
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.
picnictutorials — 2013-04-22T10:46:19-04:00 — #2
Use the 3rd one down http://www.websitecodetutorials.com/code/htaccess/301-permanent-redirect-old-domain-to-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]
steveorg — 2013-04-22T14:07:55-04:00 — #3
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.
picnictutorials — 2013-04-22T14:40:12-04:00 — #4
It's not repeated look closer
jeff_mott — 2013-04-22T17:04:42-04:00 — #5
Don't forget parentheses.
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Apache has a Redirect directive for exactly this kind of situation.
# htaccess on domain1.com
Redirect permanent / http://www.domain2.com/
picnictutorials — 2013-04-22T18:36:59-04:00 — #6
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
jeff_mott — 2013-04-22T18:49:17-04:00 — #7
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.
picnictutorials — 2013-04-22T18:50:52-04:00 — #8
Ahh ok. Only the third? Not the 4th?
jeff_mott — 2013-04-22T18:52:57-04:00 — #9
The fourth is a redirect, not a rewrite rule. It doesn't even take regular expressions.
picnictutorials — 2013-04-22T19:15:20-04:00 — #10
Lol sorry I should of looked first I guess before asking.