Redirect Mobile Users to Mobile Version of the Site

The mobile website could be special separate mobile version of the existing website. Most oftenthis mobile version creates a subdomain to the main site, for example m.mysitename.com ormobile.mysitename.com. When the main site is visited by a mobile user, then it forwards tothe mobile site.

Diverting from the main site mysitename.com to the mobile version m.mysitename.com could be done in several ways, using PHP, JavaScript or by putting a few lines with the rules inthe file .htaccess.

In this article we will describe redirecting of mobile web browsers and mobile devices to amobile version of an existing site with the use of .htaccess file in the hosting account.

First there is a need to create a subdomain for the mobile version of your site, for example

m.mysitename.com.

Once you have created a subdomain in the directory of the main site, in .htaccess file putthese rewriting rules:

RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=mredir:0:http://mysitename.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# checks if the mobile version is loaded
RewriteCond %{HTTP_HOST} !^m\.
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
# redirects to the mobile version
RewriteRule ^ http://m.mysitename.com [R,L]

In the marked lines (3,4,24,25 and 28) change the text according to the name of the mainsite (mysitename.com) and the created subdomain (m).

Some tips for mobile version of the site

Images with an appropriate size. If the image is too small, it would not be clearly visible andcan not guess the visitor what lies behind it. If it has too large size, it may take longer to loadand it is not certain that would be displayed correctly on all mobile devices.

Navigation. According to the type of your site, you can choose a suitable navigation. If thesite has a lot of categories and subcategories, navigating through them could be more intuitiveand accessible via a text menu. If the categories on the site are not many, you can add imagesto the menu.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

reCapcha doesn't work on my WordPress site. How to fix it?

Question: I have some issues with my reCapcha on my WordPress site, how to fix it. It was just...

Is it possible to get a dedicated IP address for my webpage?

Question: Hello, Is it possible to get a dedicated IP address for my webpage? (I am planning to...

Problem with PHP WordPress memory

Question: I'm trying to increase the php memory limit to 128Mb in order to keep Woocommerce...

Ad banner module does not work in my host

Question: I installed an ad banner module, but gave me the following message:ForbiddenAccess to...

I can't access to my WP installation

Question: After copying the new site files to de main directory, I can not login into my...