如何通过只更改域名重定向URL,同时保持其他URL参数 [英] How to redirect a URL by only changing the domain name, while keeping other URL parameters
问题描述
我现在迁移我的网站到一个新的主机名和域名,我想知道,如果我也可以把任何人谁进入旧网站到新网站的任何网址,同时保持所有的URL参数。例如:
当此网址 http://www.domainA.com/blog/?p=667
,我希望他被重定向到 HTTP有人类型:?//www.domainB.com/blog/ P = 667
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
.
有没有什么办法可以做到这一点通过添加一些的.htaccess配置?
谢谢!
Is there any way I can do that by adding some .htaccess configurations?
Thanks!
推荐答案
在你的.htaccess文件试试这个:
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]
这将preserve您的URI,而从重定向domainA中到域B。
This will preserve your URI while redirecting from domainA to domainB.
这篇关于如何通过只更改域名重定向URL,同时保持其他URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!