How to redirect your website to the mobile version?

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]
%d