SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict XiledWeb's Avatar
    Join Date
    May 2005
    Location
    Nashville
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    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!

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,083
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The HTTP_HOST is supposed to be the host only, i.e. no schema and no path.

    Code:
    RewriteEngine On 
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
    RewriteRule ^ – [CO=mredir:0:www.maindomain.com]
    
    RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/mobile/
    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
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •