Apache Mod-Rewrite:为什么这个URL不被过滤

我想阻止iPad连接到我的服务器,只允许iPhone。 这个mod_rewrite脚本允许这个错误是什么?

#Prevent non-iPhones from connecting to the server. #RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone2C1.* [NC] #RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone3C1.* [NC] #RewriteRule () http://www.xyz.com/ [R,NC,L] #The next line prevents version 4.0 RewriteCond %{HTTP_USER_AGENT} .*801.293.* [NC] #The next line prevents version 3.13 RewriteCond %{HTTP_USER_AGENT} .*705.18.* [NC] #The next line prevents version 3.21 RewriteCond %{HTTP_USER_AGENT} .*702.405.* [NC] #The next line prevents version 3.2 RewriteCond %{HTTP_USER_AGENT} .*702.367.* [NC] #Require iPhones to be 3GS or iPhone 4. RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone2C1.* [NC] RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone3C1.* [NC] 

有问题的设备有这样的用户代理:

  Apple-iPad1C1/803.148 

RewriteCond条件在默认情况下使用逻辑“ 与”来应用,并且您需要使用“ 或”,因为您指定要阻止的版本,而不是要允许的版本:

 #The next line prevents version 4.0 RewriteCond %{HTTP_USER_AGENT} .*801.293.* [NC,OR] #The next line prevents version 3.13 RewriteCond %{HTTP_USER_AGENT} .*705.18.* [NC,OR] #The next line prevents version 3.21 RewriteCond %{HTTP_USER_AGENT} .*702.405.* [NC,OR] #The next line prevents version 3.2 RewriteCond %{HTTP_USER_AGENT} .*702.367.* [NC,OR] #Require iPhones to be 3GS or iPhone 4. RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone2C1.* [NC,OR] RewriteCond %{HTTP_USER_AGENT} !.*Apple-iPhone3C1.* [NC,OR] RewriteRule .* http://destination.example.com/ [R,NC,L] 

我想你错过了一个RewriteRule

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

浏览器依赖内容描述:

至less对于重要的顶级页面,有时需要提供最佳的依赖于浏览器的内容,即,必须为最新的Netscape变体提供最大版本,Lynx浏览器的最小版本以及所有其他版本的平均function版本。

解决scheme:我们不能使用内容协商,因为浏览器不提供这种forms的内容。 相反,我们必须在HTTP头“User-Agent”上进行操作。 以下condig会执行以下操作:如果HTTP头“User-Agent”以“Mozilla / 3”开头,则页面foo.html将被重写为foo.NS.html,并且重写将停止。 如果浏览器是版本1或2的“Lynx”或“Mozilla”,则URL变为foo.20.html。 所有其他浏览器接收页面foo.32.html。 这由以下规则集完成:

 RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* RewriteRule ^foo\.html$ foo.NS.html [L] RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* RewriteRule ^foo\.html$ foo.20.html [L] RewriteRule ^foo\.html$ foo.32.html [L]