Tuesday, 27 November 2012

Mobile Website Redirect

Hi Guys,

Today is about - "Mobile" - 

If you've created a mobile version of your website, you'll need to be sure that you redirect your mobile visitors to your mobile website.For example, if someone visits domain.com on their phone, you'll need a way to redirect them to m.domain.com (the mobile version of your site).

If you are running a Content Management System (such as WordPress or Joomla), there may be plugins already available that help with handling mobile visitors.



Javascript Method

Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You can use the following code to do this:

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

Note:
Please keep in mind however that if the user does not have javascript enabled, this will not work.



.htaccess redirects

You can use a .htaccess redirect to transfer visitors based upon mime types that their browser accepts. For example, if the user's browser accepts mime types that include WML (Wireless Markup Language), then most likely it is a mobile device.
The code below should be placed in your .htaccess file:
RewriteEngine On
# Check for mime types commonly accepted by mobile devices
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]


Like this Article?





No comments:

Post a Comment