As a developer you might want to redirect your web version of the site to mobile version. As we know that all of us get’s quite busy with our day to day schedules, but we really want to be connected with world via internet on the move, and while leaving in the era of mobile devices it is all possible now a days. You simply have to follow very simple steps to redirects any user to the mobile version form web version of your website or vice versa:

Redirection can be done from both sides:

1. Redirect user to Mobile Version.
2. Redirect user to Web Version.

1. Redirect from Web Version to Mobile Version:

Navigate to header.php of your Web version & place the following code in <head> section:

<script language="javascript">
var query = window.location.search.substring(1);
var redirect = getQueryStringParameterByName(query, "redirect");

if (redirect!="temp")
{
 var redirectagent = navigator.userAgent.toLowerCase();
 var redirect_devices = ['vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'blackberry', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'iphone', 'android', 'htc', 'dream', 'webos', 'bolt', 'nintendo'];
 for (var i in redirect_devices) 
 {
  if (redirectagent.indexOf(redirect_devices[i]) != -1) 
  {
	location.replace("http://mobile.yoursitename.com");
  }
 }
}

function getQueryStringParameterByName(queryString, paramName) 
{
 tokens = queryString.split("&");
 if (tokens!=null)
 {
  for (i=0;i<tokens.length;i++) 
  {
   ft = tokens[i].split("=");
   if (ft[0] == paramName) 
   {
	if (ft[1].indexOf("%20",0)>0)
        {
	 var returnValue = ft[1].replace("%20"," ");
	 returnValue = returnValue.replace("%20"," ");
	 return returnValue;
	}
	return ft[1];
   }
 }
return "";
}
}</script>

In the above code we’ve used location.replace(“http://mobile.yoursitename.com”);
You can replace “http://mobile.yoursitename.com” by your mobile site URL.

2. Redirect from Mobile Version to Web Version:

Add the following code in footer.php of your mobile version of the site:

<a target="_blank" href="http://yoursitename.com/index.php?redirect=temp">Full Site</a>

In the above code we’ve used “http://yoursitename.com/index.php”. You can replace that by the name of your site(Web Version).

What are you waiting for?? Employ the above code and do the redirection.

Related posts:


  • Arvind

    That’s some cool info. Good post.

  • arjita

    Very useful.

  • http://download.cnet.com/Free-Iso-Burner/3000-2646_4-75628059.html iso software

    1 of 2 things, first I think your correct and second I think you really know how to write so people understand what you are trying to say. a+ keep up the fantastic work.

  • http://www.lesbijouxdemaeva.fr/colliers-ouverts-xsl-355.html http://www.lesbijouxdemaeva.fr/

    Keep functioning, terrific job!

  • http://bococreative.com BOCO Creative

    Nice, straight-forward way of handling this. Thanks for sharing!

  • hofit

    when I try to navigate in the full site with the mobile device all the menu items redirects back to the mobile version. any ideas?

  • marco

    Great!
    The only problem is when I go to the desktop version (by your link) I arrive to my home page and after the first click I’m redirect to mobile version. ???
    Thanks

    • http://www.tips4developer.com/ Amit Verma

      Hi Marco

      It works all perfect, here is 1 of my developed site with the same code implemented, you can have a look – http://www.fasada.ca/ , and let me know your feed back.

  • thenetguruz

    Thanks! works perfect.