Redirect Web Visitors to Mobile (RWVM)

If you have created a mobile version of your website, you need to make sure that you redirect your mobile visitors to your mobile website. For example, if someone visits domain.com on their mobile phone, you will need a way to redirect them to the  m.domain.com mobile version of your site created on a subdomain named "m".

What does it look like to switch to the mobile version?

If you think about how your redirects actually work, in theory it makes sense -  "If the user is on a mobile device, redirect them to the mobile version of the site" . The problem is that when people visit your website, their web browser doesn't know whether,  "I'm a mobile device"  or  "I'm a desktop computer" . Instead, the browser identifies itself by providing a "user-agent", which includes the browser name, version, and other information about your operating system.

To redirect mobile visitors, you need to determine whether their browser is a web browser on a mobile device or not. You can determine which browser the visitor is using. You can also look at other things like their screen resolution and whether they accept common file types for mobile devices. Below we have listed some methods you can use to redirect visitors to the mobile version of your website.

Using plugins for redirects

If you are running a Content Management System (like WordPress or Joomla), there may be plugins available that help handle mobile visitors. The best way to find these plugins is to search Google or search the software website.

Javascript method window.location

Mobile phones usually have small screen widths, so you should redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You place this code in the header section of your main website. That way when your site is visited, the javascript will see the browser width and redirect to the appropriate site.

We will discuss this issue technically separately in another post, because the emphasis on this topic is on .htaccess implementation.

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

.htaccess URL rewrite redirects

You can use .htaccess redirects to redirect visitors based on the MIME types that the browser supports. For example, if a user's browser accepts a mime type that includes WML (Wireless Markup Language), then it is most likely 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]

Good luck!


Post a Comment

Previous Next

نموذج الاتصال