Circumvent mobile redirects

Redirecting users to a mobile website when they are using a mobile device can be useful, but there may be particular pages that you want to ensure all of your users can reach, whether or not they're mobile. There are two primary methods to achieve this: redirects in .htaccess, and desktop cookies.

Redirects in the .htaccess file

One relatively easy way to redirect users to a particular page is to allow the server to rewrite the incoming request using the .htaccess file.

SetEnvIf Request_URI !"somepage$|somepage\/" DO_REDIRECT Header set X-AH-Mobile-Redirect "http://mobile.mysite.com" env=DO_REDIRECT

On Acquia Cloud, the Varnish Configuration Language (VCL) provides for a workaround for mobile redirects using a desktop cookie. This allows mobile browsers to view the full version of a site.

Drupal 7

Paste the following code into a custom block that appears on every page, or alternately you can place the code into a custom theme file (such as page.tpl.php):

 

<a href="#">View full site</a>
<script type="text/javascript" src="misc/jquery.cookie.js"></script> <script type="text/javascript">  $=jQuery;  $(document).ready( function() {    $('#view_full_site_link').click(function(){    var $this = $(this);     $.cookie('X-UA-Device-force', 'pc', { domain: '.example.com' });    window.location.replace("http://example.com");    })});</script> 

 

You can replace pc with mobile or tablet to load the mobile or tablet device versions instead of the desktop version.

Drupal 6

Use jQuery Cookie or jQuery cookie on GitHub and the following code snippet. Place the jquery.cookie.js in your mobile theme's path.

 

<a href="#">View full site</a>
<script language="JavaScript" src="<?php print path_to_theme() . '/jquery.cookie.js'; ?>"></script< <script language="JavaScript"<  $(document).ready( function() {    $('#view_full_site_link').click(function(){    var $this = $(this);     $.cookie('X-UA-Device-force', 'pc', { domain: '.example.com' });    window.location.replace("http://www.example.com");    })});</script> 

 

You can replace pc with mobile or tablet to load the mobile or tablet device versions instead of the desktop version.

Contact supportStill need assistance? Contact Acquia Support