How To Set Up Mobile Detection and Redirection

This is the Mobile Redirection process for Apache servers. If you have other types of hosting then you will need to contact your host to see how they might do it. I assume that you have already set up a Subdomain (usually starting with "m." from your normal domain), and from there you can redirect your subdomain to the mobile site.

TWO METHODS

First Method: Javascript

Paste the code below in the <head> section of your normal website. This is a Java script code that will redirect people to your mobile based websitebased on the dimensions of their screen size (600px in this case.) Place the code right below the <title></title> tag and replace m.jingo.me with the URL of your mobile website.

<script type="text/javascript">
<!--
if (screen.width <=600) {
document.location =
"http://m.jingo.me";
}
//-->
</script>

Second Method: HTACCESS file update

Step 1: .HTACCESS Code



If you have an existing .htaccess file then you may not need the first line "RewriteEngine On"

RewriteEngine On

# make sure you set the directory properly (even if using a subdomain)
RewriteCond %{REQUEST_URI} !^/mobile_site/.*$
# the next many lines are is the actual mobile detection
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|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] #*SEE NOTE BELOW

# To redirect mobiles to directory use this and remove the hash in front of the next line
# RewriteRule ^(.*)$ /mobile_site/$1 [L,R=302]

# To redirect mobiles to new site or sub domain enter it in the line below and remove the hash. Make sure that there is a Back-slash before any full stops.
RewriteRule ^(.*)$ http://m\.YOURSITE\.com/$1 [L,R=302]


Step 2: META Tag Update

Enter this Meta Tag in your HEAD section, usually on your index page but best if it can be done on all pages of your site.



<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>


Credits: More information


Once you have this set up then the only other thing remaining is to ensure your subdomain is set up to redirect to your new mobile site. This can be achieved using your Admin panel inside Cpanel, or ask your host to set it uip for you. They will need to know your current domain and your mobile domain, and they can simply link the two together.