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.
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]
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.
It's not repeated look closer
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/
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.
Ahh ok. Only the third? Not the 4th?
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.
This topic is now closed. New replies are no longer allowed.