So you want to redirect that shinny new mobile site? No problem! I’ll show you how to detect mobile browsers in a few simple steps. When I first started designing mobile sites, I searched for the easiest way to redirect my sites and found a lot of fluff. I played around with different scripts and then found gold. The script below will detect a mobile browser and is super easy to implement.
Enough talk, let’s get into the good stuff:
Detect Mobile Browser Script Instructions
- Visit Detect Mobile Browser and download the script. Just right click on the Script link and click Save As. Save it to your desktop. (Rename the file to redirection_mobile.js if it has any other name)
- FTP into your site and make a folder in the root called js. My folder is located at https://mobilewebrockstar.com/js. Upload the file downloaded in Step 1.
- Now copy and paste this piece of code in between the (A bunch of code will be here) of your homepage:
And that’s it! Super easy to do and you’ll be soon rocking your new mobile site.
Setup a Mobile Subdomain
After your phone detects a mobile browser you will need to redirect them somewhere. I send my sites/clients sites to a m.theirsite.com domain (subdomain). You might have already setup a mobile subdomain but if not, then here are the instructions. If you’re using CPanel (my host is HostGator and they use CPanel) then follow these steps. If not the process might be similar. If you’re not sure then email your web host that you want to create a subdomain and they should be able to sent you instructions.
- Log into your CPanel.
- Under Domains click Subomains.
- Type in m for the subdomain. IMPORTANT! I originally screwed this step up. Your root is going to be yoursite/m. Might even be (public_html/yoursite/m).
- Now just copy your mobile files to that m folder on your host. If you don’t have a m folder then create one in the root of your site.
You’re mobile subdomain is now setup and ready to rock!
Detect Mobile Browser VIDEO
It’s super easy to setup this detect mobile browser script. Just follow the instructions in the video.
The mobile web is exploding and will soon be the main way people view the internet. If you’re creating a mobile site for yourself or you clients then you need to redirect them to their mobile site. This is the quickest and easiest way I found to detect mobile browsers. I will update this page if I come across other solutions.
Still having a mobile redirect problem? Let us know and we’ll help you out.