Skip to content

Instantly share code, notes, and snippets.

@JKirchartz
Created April 22, 2011 14:33
Show Gist options
  • Save JKirchartz/936783 to your computer and use it in GitHub Desktop.
Save JKirchartz/936783 to your computer and use it in GitHub Desktop.
Mobile Redirect
######################################################
# Redirect to separate directory for mobile site
######################################################
# Don't redirect if we're already there!
RewriteCond %{REQUEST_URI} !^/mobile/.*$
# Check Cookie to (en|dis)able redirect to mobile or stay on desktop
RewriteCond %{HTTP_COOKIE} !^.*mobile.*$ [NC]
# Check accept header for tell-talse signs of mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
# Check User Agent for known mobile browsers
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini|IEmobile|DoCoMo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-|ipad|ipod|iphone"[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\.|mobile safari|android"[NC]
# Rewrite the URL to that of the mobile directory
RewriteRule ^(.*)$ /mobile/ [L,R=302]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment