1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

.htaccess Help...Please!

Discussion in 'BlackHat Lounge' started by Andre2812, Dec 15, 2012.

  1. Andre2812

    Andre2812 Registered Member

    Joined:
    Apr 8, 2009
    Messages:
    51
    Likes Received:
    11
    Home Page:
    Can anyone help with regards to the required directives in an htaccess file for automatically redirecting mobile users to an installed mobile site?

    I have the htaccess directives below - that assumes the mobile site is installed on a subdomain in this instance
    Code:
    [URL]http://m.yourdomain.com[/URL]
    - however our mobile site is installed in a directory eg.
    Code:
    [URL]http://www.yourdomain.com/mobi/[/URL]
    This is what I have, but it is creating a redirect loop
    Code:
    RewriteEngine onRewriteBase /
    # Check if this is the noredirect query string
    RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
    # Set a cookie, and skip the next rule
    RewriteRule ^ - [CO=mredir:0:www.yourdomain.com]
    
    
    # Check if this looks like a mobile device
    # (You could add another [OR] to the second one and add in what you
    #  had to check, but I believe most mobile devices should send at
    #  least one of these headers)
    RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP:Profile}       !^$ [OR]
    RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
    RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
    
    
    # Check if we're not already on the mobile site
    RewriteCond %{HTTP_HOST}          !^m\.
    # Can not read and write cookie in same request, must duplicate condition
    RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
    
    
    # Check to make sure we haven't set the cookie before
    RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
    
    
    # Now redirect to the mobile site
    RewriteRule ^ http://m.yourdomain.com [R,L]
    Even when changing the last rewrite rule to the
    Code:
    [URL]http://www.yourdomain.com/mobi/[/URL]
    the redirect still exists.

    Any help will be appreciated......

    Andre
     
  2. Andre2812

    Andre2812 Registered Member

    Joined:
    Apr 8, 2009
    Messages:
    51
    Likes Received:
    11
    Home Page:
    Anyone? Or if you could point out any resources - this would be really appreciated....