Redirecting visitors of mobile devices

How to redirect visitors of mobile devices to mobile web-site version by means of htaccess

Examples of User-Agent mobile devices.
It is convenient if you are automatically redirected to mobile version when you use a mobile phone to enter the web-site.

How to define user from mobile device

We need an opportunity to change settings of web-server with help of file htaccess. In addition, ModRewrite must be turned on.

In order to identify we use value of User-Agent that is given by browser at page request. Each browser on default has its own value of that field.
Users which User-Agent corresponds to mobile browsers are redirected to mobile version.

In htaccess it looks like that

RewriteCond %{HTTP_USER_AGENT} (?i:midp|samsung|iphone|android)
RewriteRule ^(/)?$ [R=301]

Testing the redirection

We can check up the redirection performing by means of mobile phone or program


Or shorter list:

RewriteCond %{HTTP_USER_AGENT} (?i:midp|samsung|nokia|j2me|avant|docomo|novarra|palmos|palmsource|opwv|chtml|pda|mmp|blackberry|mib|symbian|wireless|nokia|hand|mobi|phone|cdm|upb|audio|SIE|SEC|samsung|HTC|mot-|mitsu|sagem|sony|alcatel|lg|eric|vx|NEC|philips|mmm|xx|panasonic|sharp|wap|sch|rover|pocket|benq|java|pt|pg|vox|amoi|bird|compal|kg|voda|sany|kdd|dbt|sendo|sgh|gradi|jb|dddi|moto|iphone|android)

Disadvantages of given redirection method

The basic disadvantage – a visitor will not be able to go to your main web-site from mobile device if it wants. It will be redirected to mobile version, and it is not always convenient.

to top