Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created November 30, 2011 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipadsmith/1410885 to your computer and use it in GitHub Desktop.
Save phillipadsmith/1410885 to your computer and use it in GitHub Desktop.
Mobile site redirection using mod_rewrite (with option for smart phones vs. feature phones)
# If the visit is from a mobile user agent, and there's no fullsite cookie, redirect and stop
# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
# a bunch of user agent tests for very basic phones
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\."[NC,OR]
# Slightly more advanced phones, but probably still worth sending them to the simple HTML site
RewriteCond %{HTTP_USER_AGENT} "blackberry|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{HTTP_COOKIE} !^.*fullsite=yes.*$ [NC]
RewriteRule ^/?(.*)$ http://mo.domain.com/$1 [L,R=302]
# For "smart" phones (you might want to take iPad out of the following list)
RewriteCond %{HTTP_USER_AGENT} "android|ipad|iphone|ipod" [NC]
RewriteCond %{HTTP_COOKIE} !^.*fullsite=yes.*$ [NC]
RewriteRule ^/?(.*)$ http://m.domain.com/$1 [L,R=302]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment