Redirect a user to a mobile version of a website

March 2017


Redirect your users to a mobile version of your website using htaccess

If you have a mobile version of your website, then it may be that you want to automatically redirect your visitors to the latter (each time they connect via theire mobile)
  • To do this there are several solutions, the simplest is to use the .htaccess file and write the following lines of code:


RewriteCond %{HTTP_USER_AGENT} "ipod|iphone|ipad|android|palm" [NC]    
RewriteRule (.*) http://m.commentcamarche.net/ [R=301,L]   
  • Here the mobile user are redirected to: m.commentcamarche.net
  • To change the domain name, simply edit the second line!



Related


Published by jak58.
This document, titled "Redirect a user to a mobile version of a website," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).