Redirect to Mobile Site throwing up Too Many Redirects Error in Safari

Hi there,

We receive a lot of mobile specific traffic so are working on setting up a redirect in .htaccess from homepage to mobile homepage. The full codebase in our .htaccess is:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ – [CO=mredir:0:http://www.maindomain.com]

RewriteCond %{HTTP_HOST} !^http://www.maindomain.com/mobile/\\.com$ [NC]
RewriteCond %{REQUEST_URI} !\\.(jpg|css|png|gif)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]
RewriteCond %{HTTP_COOKIE}  !mredir=0 [NC]
RewriteRule ^ http://www.maindomain.com/mobile/? [R,L]

Where maindomain.com is our main site and maindomain.com/mobile-site/ is where we want the redirect to go.

The issue we’re having is that Safari is giving us a ‘too many redirects’ error. Just tested in Chrome on iPhone 4 and the error code is: ERR_TOO_MANY_Redirects

Any help would be appreciated! :slight_smile:

The HTTP_HOST is supposed to be the host only, i.e. no schema and no path.


RewriteEngine On 
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ – [CO=mredir:0:[color="red"]www.maindomain.com[/color]]

RewriteCond %{HTTP_HOST} !^[color="red"]www\\.maindomain\\.com[/color]$ [NC]
[color="red"]RewriteCond %{REQUEST_URI} !^/mobile/[/color]
RewriteCond %{REQUEST_URI} !\\.(jpg|css|png|gif)$ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) [NC]
RewriteCond %{HTTP_COOKIE}  !mredir=0 [NC]
RewriteRule ^ http://www.maindomain.com/mobile/? [R,L]

Try that and we’ll take it from there :slight_smile: