Apache Mod-Rewrite: Por que esse URL não está sendo filtrado

1

Gostaria de evitar que os iPads se conectassem ao meu servidor e permitissem apenas iPhones. O que há de errado com esse script mod_rewrite que está permitindo isso?

#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]

O dispositivo incorreto tem isso para um agente do usuário:

 Apple-iPad1C1/803.148 
    
por random65537 23.11.2010 / 16:21

2 respostas

2

As condições RewriteCond são aplicadas por padrão usando um AND lógico, e você precisa usar OR desde que esteja especificando quais versões bloquear, em vez de quais versões permitir:

#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]
    
por 23.11.2010 / 21:29
0

Acho que você está perdendo uma RewriteRule

link

Browser Dependent Content Description:

At least for important top-level pages it is sometimes necessary to provide the optimum of browser dependent content, i.e. one has to provide a maximum version for the latest Netscape variants, a minimum version for the Lynx browsers and a average feature version for all others.

Solution: We cannot use content negotiation because the browsers do not provide their type in that form. Instead we have to act on the HTTP header "User-Agent". The following condig does the following: If the HTTP header "User-Agent" begins with "Mozilla/3", the page foo.html is rewritten to foo.NS.html and and the rewriting stops. If the browser is "Lynx" or "Mozilla" of version 1 or 2 the URL becomes foo.20.html. All other browsers receive page foo.32.html. This is done by the following ruleset:

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]
    
por 23.11.2010 / 16:37