我使用以下代码到我的oldsite,301将所有流量重定向到我的新网站 .
.htaccess - 位于oldsite.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^newsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/ [R=301,L]
</IfModule>
Redirect 301 / http://newsite.com/
如果url不包含问题掩码符号“?”,则上述.htaccess代码仅起作用 .
例如 .
Example 1 is OK
http://oldsite.com/whatever - > 301重定向到http://newsite.com/
但是,如果我要输入:
Example 2 is NOT OK
http://oldsite.com/?whatever-> 301重定向到http://newsite.com/?whatever
它应该重定向到索引站点,就像那样
http://oldsite.com/?whatever - > 301重定向到http://newsite.com/
和
Example 3 is NOT OK
http://oldsite.com/whatever?something - > 301重定向到http://newsite.com/?something
它应该重定向到索引站点,就像那样
http://oldsite.com/whatever?something - > 301重定向到http://newsite.com/
- 为什么会这样?
和
- 我该如何面对这个问题?
1 回答
重定向和重写规则都是多余的 . 使用这样的规则 . 要删除
query string
,您需要在重写的末尾添加问号 .