[英].htaccess 301 redirect doesn't work due to question mark symbol “?”
我在我的舊網站上使用以下代碼將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/
上面的.htaccess代碼僅在URL不包含問題掩碼符號“?”的情況下有效。
例如
示例1可以
但是,如果我要輸入:
示例2不好
http://oldsite.com/?無論 -> 301重定向到http://newsite.com/?
它應該像這樣重定向到索引站點
http://oldsite.com/?什么 -> 301重定向到http://newsite.com/
和
示例3不好
http://oldsite.com/whatever?something- > 301重定向到http://newsite.com/?something
它應該像這樣重定向到索引站點
http://oldsite.com/任何內容 -> 301重定向到http://newsite.com/
和
重定向和重寫規則都是多余的。 像這樣使用您的規則。 要刪除query string
您需要在重寫器的末尾添加一個問號。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^newsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/? [R=301,L]
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.