How To Redirect Users To A Mobile Web Page?

The standard redirection for the users who are connecting from a smartphone or a mobile device is by utilizing a m.yourdomainname.com. Here the users who are coming from these mobile devices needs to see mobile website so they will be redirected appropriately.


There are some mobile devices that will not be having the indicators that they are on a mobile, here the process of redirection can be tricky. The browsers on each device will be indicating the user agent which will be telling the server its browser name, version as well as other general information. Based on it you will be able to determine if it is mobile visitor or not and then you will be able to redirect it accordingly.

There are couple of options by which you will be able to redirect the mobile users correctly:


By Use of the Plugins

If you have been running a CMS like a WordPress or a Drupal on a web hosting platform, then they will often be having a plugin which is available which will help in handling the mobile users. You will be having an option of searching it online or through the marketplace of the CMS for finding out more there.





Another Option is JavaScript Redirection

There are mobile devices which will usually be having a small screen settings, hence you will be able to redirect the visitors to a mobile website if they are having a screen width of less than or equal to 800 pixels. The below code will allow you to do the redirection.

<script type="text/javascript">
<!--
if (screen.width <= 800) {
window.location = "http://m.domain.com";
}
//-->
</script>

 

When it was tested on a smart phone the resolution of the screen was differentiated based on how the phone was held. As the screen was automatically flipping. For getting the best results, one must have to test it on different smart phones until one gets the right settings for the website. One must always remember that if the javascript is not been enabled then it will not work.

.htaccess for Redirection

It is one of the most common redirect format available. You will be able to use the .htaccess redirects for transferring the users which is based on the MIME types where the browser accepts. One of the example is if the browser is accepting things like WML (Wireless Markup Language) then it is a mobile device which can be redirected safely.
The code which is shown below should be placed in the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]

These were the simple ways by which you can redirect the users to a mobile device.