【问题标题】:Apache mod_rewrite %{HTTP_USER_AGENT} not equal + or condition (list)Apache mod_rewrite %{HTTP_USER_AGENT} 不等于 + 或条件(列表)
【发布时间】:2012-12-17 19:29:33
【问题描述】:
我现在的情况是这样的:
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
我想知道如何将这个条件换成if not 上述值之一。
我对这样的事情很生气:
RewriteCond %{HTTP_USER_AGENT} !="android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
但它不起作用。
【问题讨论】:
标签:
apache
.htaccess
mod-rewrite
redirect
【解决方案1】:
问题是opera 和mobile 之间有一个空格,这会导致 mod_rewrite 将其解析为多个参数。尝试在! 中使用括号而不是引号并转义空格:
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|ipad|iphone|ipod|iemobile|opera\ mobile|palmos|webos|googlebot-mobile) [NC]
【解决方案2】:
非常接近你不需要在否定!之后添加=。
RewriteCond %{HTTP_USER_AGENT} !"android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]