IPad / iPhone browser sniffer with mod_rewrite and redirection; "too many redirects"

I'm trying to create a browser sniffer for the version of Mobile Safari, the problem is that redirecting creates an infinite loop, obviously, and I'm wondering if there is a way to do this:

http://mydomain.com (or any other requets_uri) [301] → http://mydomain.com/ipad

Here is 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]

Refresh . Here is my (modified) full mod_rewrite rule set:

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 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 answers, I came to the following solution that I am posting for those who have the same problems:

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 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]
+2
source share
1 answer

RewriteCond , %{REQUEST_URI} "ipad". :

RewriteCond %{REQUEST_URI} !^/ipad
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ /ipad [R=301,L]

"ipad" - , . RewriteBase, , , , - , mod_rewrite .

. , , , %{REQUEST_URI} , , . , mod_rewrite , . , :

RewriteEngine On
RewriteBase /

# iOS redirection.
# Make sure the URL hasn't already been rewritten internally
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteCond %{REQUEST_URI} !^/ipad
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ /ipad [R=301,L]

# If the requested URL does not exist (it 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]
+2

All Articles