How to redirect your website to the mobile version?

Published on June 23, 2013 by abundantcode

Filed under HTML

Last modified June 23, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 6895 times

Accessing the websites in the mobile or smartphones are very common these days. Companies tend to have the mobile version of the website which targets the smaller screens.

If you are one of those users who have created the mobile version of your main website, you should take care that each time the user visits the website from their mobile phones, it should redirect to the mobile website.

How to redirect your website to the mobile version?

For example, when the website domain name is abundantcode.com, one may want to redirect to m.abundantcode.com

One of the simple ways to redirect the visitors to the mobile version of the website is based on the MIME type which the browser supports.

Generally, the mobile browsers support the mime type WML which is the Wireless Mark-up Language. We could identify if the request came from the mobile using this.

The htaccess file can be used to redirect in this case.

Below is a sample code snippet which can be placed in the .htaccess which redirects to the mobile version of the website.

RewriteEngine On

# Accepted mime types by mobile and smartphones

RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]

RewriteCond %{REQUEST_URI} ^/$

RewriteRule ^ http://m.abundantcode.com%{REQUEST_URI} [R,L]

Leave a Comment


x

You might be Interested in these Posts

How to Check if a file exists in Windows Storage in UWP ?

Do you want to know if a file exists in the Windows Storage from your Universal Windows Platform (UW...

How to Redirect to Another Page in ASP.NET Webform ?

Below is a sample code snippet that demonstrates how to redirect to another page in ASP.NET webform....

How to decode a base64 string in C#?

Here's a sample code snippet demonstrating how you can easily decode a base64 encoded string in C#. ...