I'm trying to create a browser sniffer for Mobile Safari version, the problem is that the redirection creates an infinite loop, obviously, and I'm wondering if there's a way to do this:
http://mydomain.com (or any other requets_uri) [301]-> http://mydomain.com/ipad
Here's the snippet I'm using:
RewriteCond %{REQUEST_URI} !^ipad #Trying to set the condition "if /ipad is not the request_uri, but it doesn't work
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ ipad [R=301,L]
Update: Here is my (modified) full set of mod_rewrite rules:
RewriteEngine On RewriteBase /
# iOS redirection.
RewriteCond %{REQUEST_URI} !^/ipad
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ /ipad [R=301,L]
# If the requested URL does not exist (it's likely an agavi route),
# pass it as path info to index.php, the Agavi dispatch script.
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule (.*) index.php?/$1 [QSA,L]
Update 2: FINAL; Thanks to the replies, I've come to the next solution which I'm posting for anybody having the same issues:
RewriteEngine On
RewriteBase /
# iOS redirection.
# Make sure the URL hasn't already been rewritten internally
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteCond %{REQUEST_URI} !^/ios
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^.*$ /ios [R,L]
# If the requested URL does not exist (it's likely an agavi route),
# pass it as path info to index.php, the Agavi dispatch script.
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule (.*) index.php?/$1 [QSA,L]