Redirect to Mobile Website – SUPER Easy Tutorial

I spent literally hours searching for a good, easy-to-follow how-to on setting up a javascript redirect on your website so that mobile visitors get sent to your mobile page to no avail. It needed to be extremely clear and with great examples and I wanted a method that DIDN’T rely on screen-size because, well… That’s just stupid. You don’t want to redirect desktop visitors who have their browser small!

Okay then, let’s get to it. We are going to be using the JS-Redirection-Mobile-Site script found at Git Hub here. Now, before you click that link and get yourself all confused, I’m going to break down everything for you. Okay, first things first. Download redirection-mobile.js here. Just highlight the text, copy it, and then create a new text document in a folder in your site called “js” and name it redirection-mobile.js. Good, we are almost done. Now, in the <head> section of the page you are looking to redirect, paste this:

Easy stuff. Now replace “urltoredirectto.com” with, well… The URL you would like to redirect to. Now upload this to your server, and you are good to go!

What this will do is redirect most mobile visitors (but not tablets) to this URL. And it works great, because if they go to that mobile site, and then click a link to come BACK to the page they were just redirected from, it won’t redirect them again, allowing them to view the regular page.

I’ve had many requests for instructions on including a tablet redirect as well, so I’m going to show you how to do that. Setting tablet_redirection to “true” will redirect tablet users as well. If you would like to specify a separate location for tablet users, you can do that by entering a value for “tablet_host”. So the code will now look like:

For a full list of parameters you can use, view the github page I linked to earlier and find the readme there, it has a detailed explanation of everything. I hope this helps someone avoid all the trouble and work I had to go through to figure this out! Thanks for stopping by.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.