Redirect Mobile Users To Mobile Website

How To Redirect Mobile Users On Your Website
If you have a separate mobile website for your mobile/handheld users you can use this simple JavaScript or .htaccess method to redirect users based on their screen width to your mobile website.
However it is recommended to use Responsive design instead of a separate mobile URL like m.example.com.
But, if you still prefer a separate mobile website and have enough reasons for it lets redirect mobile users to mobile website.

Redirect users: The Java Script

You can use the code above which detects if the users screen is less then 900px he/she will be redirected to the mobile website.
Include the snippet above in your head tag.
on some smart phone or tablets width may depend on how the user is holding a phone(portrait or landscape), so it will be better to check some major smart phones width.

<script>// <![CDATA[
if (screen.width <= 900) {
     document.location = "http://m.example.com";
  }
// ]]></script>

You can change m.example.com to your mobile website URL, also you can change the width parameter which is 900 in our case.

Mobile redirect: .htaccess URL rewrite method

If you have access to ftp you can create a .htaccess file and redirect users to mobile site by checking MIME types.
RewriteEngine On
# Check for mime types commonly accepted by most of the mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

Conclusion: Think about yourself and your users

Redirecting mobile users to mobile website is a great approach but you have to create a separate mobile website, instead you can make your website and let the same content be optimised for mobile users.
Also some redirection's might not be good for seo.

Comments

Popular posts from this blog

Show Full Post on Front Page of Ghost, Not Excerpt

Video Blogger Templates

5 Beautiful Dark Blogger Templates