如何使用htaccess将查询字符串附加到url

时间:2014-02-04 13:06:57

标签: .htaccess url-rewriting

我想根据用户代理

将查询字符串附加到我的所有网址

例如:xyz.com/buy.html to xyz.com/buy.html?eq = mobile`

xyz.com/more/buy.htmlxyz.com/more/buy.html?eq=mobile

#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC] 

正在检测移动浏览器,但无法写出正确的RewriteRule

1 个答案:

答案 0 :(得分:0)

您需要确保查询字符串不存在:

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC] 
RewriteCond %{QUERY_STRING} !^eq=mobile
RewriteRule ^(.*)$ $1?eq=mobile [L,QSA]