问题
I'm now migrating my website to a new host and domain, and I want to know if I can redirect anyone who enters any URL of the old website to the new website, while keeping all of the URL parameters. for example:
When somebody types in this url http://www.domainA.com/blog/?p=667
, I want him to be redirected to http://www.domainB.com/blog/?p=667
.
Is there any way I can do that by adding some .htaccess configurations?
Thanks!
回答1:
Try this in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://www.domainB.com/$1 [R=301,L]
This will preserve your URI while redirecting from domainA to domainB.
来源:https://stackoverflow.com/questions/5956844/how-to-redirect-a-url-by-only-changing-the-domain-name-while-keeping-other-url