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
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ ipad [R=301,L]
Refresh . Here is my (modified) full mod_rewrite rule set:
RewriteEngine On RewriteBase /
RewriteCond %{REQUEST_URI} !^/ipad
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)$ /ipad [R=301,L]
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 /
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]
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteRule (.*) index.php?/$1 [QSA,L]
source
share