I'm using mobile tools and browsercap. Since we got lots of guest user boost seems to be a very efficient, simple yet fast method of caching. Boost caches static pages and redirects a user directly to the static file. This seems to be though a problem: Let's say a mobile user visits the site. Without cache he will be redirecty to the mobile Version of the site (ending in .mobi). With the cache enabled a user is directly forwarded to the static file, leaving out the possibility to do any PHP requests (checking if it's a browser) and redirecting the user to the mobile version.

Any idea on how to avoid/solve this problem

Comments

mikeytown2’s picture

twom’s picture

Status: Active » Needs work

Hi,

Using BOOST and mobile tools will indeed not work for the redirection. For this you will need some switching that could be more client side (JS) or at apache level (maybe this can help: http://www.idelfuschini.it/apache-mobile-filter.html)

Let us know if you find a solution for this!

Tom

ifuschini’s picture

Hi Tom,
thank you to have suggested Apache Mobile Filter for solve mobile redirect problem. In this post I add some more info:

1) The correct URL of AMF project is http://www.idelfuschini.it/en/apache-mobile-filter-v2x.html
2) The AMF is an Open Source project.
3) The AMF is a suite of modules for Apache, below a little description:

  • Detect correctly the device and pass to the other web application (php, ruby, perl ..... etc.) the capabilities as environment variables (AMFWURFLFilter)
  • Cluster Caching mode (AMFWURFLFilterMemcached)
  • Mobile Caching System (AMFMobileCaching)
  • Resize images on the fly to adapt to the screen size of the mobile devices (AMFImageRendering)
  • Switch the browser to a correct site (AMFSwitcher)
  • Carrier Detection (Vodafone, TIM, Orange etc. etc.) (AMFCarrierDetection)
  • Admin Tool (only for filesystem caching) (AMFDeviceMonitor)

4) from november 2009 is a module included in "Apache Module Registry" (http://modules.apache.org)

twom’s picture

Status: Needs work » Fixed

Great, thanks for this additional documentation!

Regards,
Tom

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vikramy’s picture

Hi,

This is also one of the solution.

http://www.projectronin.com/blog/?p=10

udvranto’s picture

Subscribing.

skolesnyk’s picture

Can you propose a solution for Nginx as a webserver instead of Apache?

thedavidmeister’s picture

Category: bug » support

since this is the first hit on google when you search "drupal boost mobile tools", i thought i'd drop a simple suggestion that you can "avoid" the problem by telling Boost not to statically cache your landing page. Users will be redirected when they hit your front page, but be served cached content everywhere else.

i just tested it, seems to be working sweet.

the solution is not perfect if a lot of your traffic is from referrals, but the alternatives suggested here have nothing to do with the Mobile Tools module or Boost, and they require a lot more tech savvy to implement/maintain. Especially the suggestion that requires maintaining .htaccess rules based on the current list of mobile phones on the market. There's no way that's future-proof.

skolesnyk’s picture

Thanks, David, for simple yet effective solution.

DocMartin’s picture

Thanks to David for this solution

I've noticed that in SIte Information, can specify a home page for the mobile site: so maybe this would be worthwhile thing to do, again helping avoid the Boost issue; and may be able to make a better home page for mobile site users.

liminu’s picture

If i undestrand i can use mobile tools with the theme switch option based on url and boost only if the redirect is by apache and disabling it in mobile tools option?

thedavidmeister’s picture

re: #12

short answer - I don't think mobile tool's redirect will work with any module that uses Drupal's "fast cache". The suggestion to use the apache redirect is a workaround as the redirect happens before Drupal is bootstrapped at all.

audster’s picture

subscribing

gundarx’s picture

A little late but here's a Javascript solution we're using for http://goaskalice.columbia.edu/

This assumes that:
"Cache pages that contain URL Variables" is disabled

The upside is Boost can be active for all pages you'd like it on (necessary for a heavily-trafficked landing page) and the user is redirected to the same page they wanted to see (ex. http://goaskalice.columbia.edu/fun-stuff goes straight to http://mobile.goaskalice.columbia.edu/fun-stuff)

  <script type="text/javascript">
  <!--
  /* For mobile detection: force dynamic page */
  if (screen.width <= 699) {
    var currentUrl = window.location.href;
    if (currentUrl.indexOf("?") == -1) {
      window.location = window.location.href + "?nocache=1";
    }
  }
  -->
  </script>

Hope this helps someone out.

Jake

gundarx’s picture

To add to the above, I have this included in page.tpl.php right under:

  <?php print $head; ?>

And before other CSS and Javascript files are loaded. This spares the user from loading those resources before they are redirected.

Jake

ifuschini’s picture

Good news for use Apache Mobile Filter for mobile redirect, now is possible to use AMF with mod_rewrite so is more easy todo this job.

For more info:

http://wiki.apachemobilefilter.org/index.php/Mod_rewrite_integration

from last my post something change, now AMF got a site:

http://www.apachemobielfilter.org

and a dedicated wiki;

http://wiki.apachemobilefilter.org

Now AMF support several device repository like WURFL, DetectRight and 51Degrees

mrP’s picture

See #1475420: Document Apache Mobile Filter and Domain Access configuration for more information about Apache Mobile Filter configuration

thedavidmeister’s picture

In response to #17, one of my clients has purchased a "managed server" package with a hosting company that won't install Apache Mobile Filter because their staff has no prior experience with the software.

For various reasons (simplifying the question of accountability mostly) we want to run any changes to server software through the hosting provider, so we had to do something simpler in the .htaccess that would work with a more "vanilla" Apache installation.

We're actually using authcache + cacherouter + memcache for this particular setup, but the underlying issue is identical to the Boost problem - the cached pages are served before Mobile Tools has the chance to do any redirects with PHP (which is a good thing overall, really).

Also, the site in question is getting traffic too heavy for us to have the luxury of removing page caching from the front page (as per my earlier suggestion in #9) so we dropped this in our .htaccess for a "quick fix"

   RewriteCond %{HTTP_HOST} !^m\.example\.com$ [NC]
   RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
   RewriteRule ^(.*)$ http://m.example.com/$1 [R=301,L]

This should also work on most shared hosting environments, so I hope this helps somebody as I still see this thread as the top google hit for "boost mobile tools".

Obviously, if another major provider invents a new smart phone, the list of user agents will have to be updated accordingly, which is the main downside of this approach over the 3rd party Apache Mobile Filter solution.

Also, this is a pretty simplified set of conditions, for example it won't redirect desktop users back to the non-mobile site and mobile users will not be able to get away from the mobile domain even if they want to (so you might want to remove ipad from the user agent check, depending on your theme). Luckily these limitations weren't such a problem for us :)

captainpants’s picture

I did a little bit of a spinoff from the solution above because I currently use a multisite installation with specific redirect rules and this does the trick. This is in D6 by the way.

My requirements were that if a url alias exists in a list, then redirect to its mobile equivalent if you have a mobile device. If a mobile device hits a url alias that is not on this list, then just redirect to the mobile homepage.

Changes to .htaccess. (This chunk of code does at the bottom of the rewrite rules in the section where you decide whether or not to serve a cached page)

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{HTTP_HOST} !^m\.(.*)$ [NC]

Note that this htaccess rule only works if you have a domain naming scheme of m.example.com

Code to put in preprocess_page

$device_info = mobile_tools_get_device();
	
if($device_info['type'] == 'mobile'){
  //Default to .com if domain is unknown
  $redirect_domain = variable_get('mobile_tools_mobile_url', 'http://m.example.com');
  $has_mobile_tools_redirect = drupal_match_path(drupal_get_path_alias($_GET['q']),variable_get('mobile_tools_redirect_exceptions', false));
		
  //redirect to mobile homepage if redirect not found on the redirection list
  if(!$has_mobile_tools_redirect)
    header('Location: ' . $redirect_domain, TRUE, 302);	
  else
    header('Location: ' . $redirect_domain.'/'.$vars['node']->path, TRUE, 302);	
}

Using this method, a mobile device will not be served a cached page when it hits the desktop site which means that it will hit that chunk of code in preprocess_page and be redirected appropriately to mobile.

bitcookie’s picture

We successfully used boost with mobile tools using the m. domain method and javascript device detection/switching. Since you can set cookies at a top level domain the device preference can be saved in a cookie, allowing the mobile user to switch to the desktop site if they need to. This provides a great benefit over the .htaccess method, which would never let a mobile user switch to the desktop site.

Check out all the steps here: http://bitcookie.com/blog/integrating-drupal-7s-boost-and-mobile-tools

Maybe some clever lad will turn our code into an addon module for mobile tools ;)