SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    htaccess rewrite/redirect help needed

    Ok - I am trying to make it so that the following occurs. Unfortunately, just adding the two lines at the end of the code for iPad doesn't work. Help!!!

    1. When you visit on a phone device, the browser should go to: http://mobile.sitename.com, which is the mobile site.
    a. When you tap full website, it should go to the full site on the phone device.
    2. When you visit the site on an iPad/paddish device, the browser should go to: http://www.sitename.com/mobile/ipad/
    a. When you tap full website on the iPad, it should go to the full site on the iPad device.

    Code:
    #Mobile detection
    RewriteCond %{QUERY_STRING} !(.*&)?nomobile [NC]
    RewriteCond %{REQUEST_URI} !\.*(jpg|png|css|this|that|otherthing)$ [NC]
    RewriteCond %{HTTP_COOKIE} !^.*nomobile.*$ [NC]
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} sitename\.com [NC]
    RewriteCond %{REQUEST_URI} ^/$
    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] #*SEE NOTE BELOW
    RewriteRule ^(.*)$ http://mobile.sitename.com [L,R=302]
    RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
    RewriteRule ^(.*)$ http://www.sitename.com/mobile/ipad/ [R=301]

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    WDG,

    Three things:

    1. The last TWO RewriteCond statements are not OR'd (the next to last should be because it's currently ANDed with the last one.

    2. The ^(.*)$ isn't used in the redirection (why capture something then not use it?) so you've stripped off the {REQUEST_URI}

    3. Only @iPad@ gets redirected to mobile/ipad/? Why the garbage on either side of iPad, why not NC and why aren't you telling the ipad directory what file(s) are being requested?

    Fix those things and you'll be on your way.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •