问题
I've got two sites, lets call them example.com and example2.com.
The website used to only be accessible via example.com but our client wanted to change their name so they registered example2.com. Now example.com and example2.com are now pointing to the same website.
I need an htaccess rule that will direct all traffic accessing the site via the old domain example.com and 301 redirect it to the new domain example2.com.
I know it's going involve at least one REWRITE_COND but I don't know what syntax I need.
回答1:
Nevermind, I figured it out. Here's my solution:
# Redirect Traffic from old domain
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]
来源:https://stackoverflow.com/questions/4830898/redirect-one-domain-to-another-on-the-same-ip