[英]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=true到http://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.