簡體   English   中英

使用htaccess從URL中刪除?query = string

[英]Remove ?query=string from URL with htaccess

我曾經有一個查詢字符串來處理移動頁面。 現在,該網站可以響應,不需要它,我需要進行301重定向,讓Google知道。

所以

http://www.example.com/aaa/bbb?fromMobile=true應該成為http://www.example.com/aaa/bbb

http://www.example.com/aaa?fromMobile=true應該成為http://www.example.com/bbb

http://www.example.com?fromMobile=true應該成為http://www.example.com

等等

我有:

RewriteCond %{QUERY_STRING} ^(?)fromMobile=true$ [NC]
RewriteRule (.*) /$1?%1&%2 [R=301,L]

但這重定向:

http://www.example.com?fromMobile=truehttp://www.example.com嗎?

如何擺脫尾隨的問號? 我已經嘗試了很多沒有喜悅的事情。

您可以使用:

RewriteCond %{QUERY_STRING} ^fromMobile=true$ [NC]
RewriteRule (.*) /$1? [R=301,L]

這是假設除了fromMobile=true之外沒有其他查詢參數。

如果還有其他查詢參數的可能性,請使用:

RewriteCond %{QUERY_STRING} ^(.+?&)?fromMobile=true(?:&(.*))?$ [NC]
RewriteRule (.*) /$1?%1%2 [R=301,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM