Posted By

ohryan on 11/24/10


Tagged

redirect htaccess mobile


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

seanpowell
mikael12
superman


.htaccess Mobile Device Redirect


 / Published in: Apache
 

This rewrite covers most mobile devices (with few false positives). When a mobile device is detected it is redirected to /m/.

  1. RewriteCond %{REQUEST_URI} !^/m/.*$
  2. RewriteCond %{HTTP_USER_AGENT} !^.*ipad.*$ [NC]
  3. RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
  4. RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox" [NC,OR]
  5. RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-|portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc" [NC,OR]
  6. RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android" [NC]
  7. RewriteCond %{REQUEST_URI} ^/$

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Attractum on January 3, 2012

I already have a non www to www redirect setup in my htaccess file and when I add your mobile code I still can't get the redirect to work. What have I done wrong?

The current redirect is:-

RewriteEngine on RewriteCond %{HTTP_HOST} ^mydomain.com$ RewriteRule ^/?$ "http\:\/\/www.mydomain.com" [R=301,L]

thanks in advance

You need to login to post a comment.