mod_rewrite %{HTTP_USER_AGENT} not equal + or condition (list)

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

My current condition goin like that:

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

I wonder how can i swap this condition into "if not" one of the values above.

I tought about something like that:

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

but its doesnt work.

回答1:

The problem is you've got a space between opera and mobile, which causes mod_rewrite to parse it as multiple parameters. Try using parentheses instead of quotes in conjunction with ! and escape the space:

RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|ipad|iphone|ipod|iemobile|opera\ mobile|palmos|webos|googlebot-mobile) [NC] 


回答2:

Pretty close you don't need to add = after the negation !.

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!