Extension:MobileFrontend/Configuring browser auto-detection

This document explains how a site admin can enable a mobile site for their mediawiki extension such that when a user visits the site from a mobile device they are automatically redirected to the mobile view rather than the desktop view.

Built-in autodetection
As of commit 5a1867e, MobileFrontend supports automatic device detection with minimal configuration. All you need to do is set: $wgMFAutodetectMobileView = true; in you LocalSettings.php. While this is the easiest method, it will almost certainly be the least performant. This solution is NOT compatible with front-end caching, as it provides no way for your cache to know the difference between a mobile view and a desktop view.

Apache Mobile Filter (AMF)
As of commit 0fb2c72d, MobileFrontend supports the Apache Mobile Filter (AMF) for device detection. You must be using the Apache webserver. Follow instructions for setup/configuration of AMF, and it should 'just work'. This functions very similarly to built-in auto detection, and will not be compatible with front-end caching without special configuration.

Webserver/proxy-cache device detection
This is what the WMF does for device detection. If you are using front-end caching, you will want to set up device detection at this layer, otherwise, set it up at the web server layer. Ultimately, you will need to set a custom 'X-Device' http request header, with the value matching one of the device types in includes/DeviceDetection.php - we recommend that you follow what we do in our Varnish configuration.

One domain for mobile and desktop views
If you are using the same domain for your desktop and mobile sites, you will want to be careful to *not* set the X-Device header for non-mobile device browsers; otherwise, everyone will get the mobile site unless they explicitly switch to the desktop view.

Separate mobile and desktop domains (Recommended)
MobileFrontend supports the usage of two separate domains for a mobile version and desktop version of the site, and this is the recommended approach. While more complicated to set up, it is ultimately easier to manage and to scale - particularly if you are using frontend caching. Follow the guidelines above for ensuring you set an X-Device HTTP header for your mobile domain, and don't bother setting an X-Device HTTP header for the desktop domain.

Then, you will need to define your mobile domain by setting  in LocalSettings.php.

You can either define a completely unique static domain for your mobile site: $wgMobileUrlTemplate = 'mobile.mydomain.com'; Or, if you use one configuration to manage multiple wikis, you could define a mobile domain template: $wgMobileUrlTemplate = '%h0.m.%h1.%h2'; Where '%h<#>' maps to a segment of the hostname of. So, if, %h0 is 'en', %h1 is 'wikipedia', %h2 is 'org'. Given this, the above  will automatically interpolate your mobile URL as 'en.m.wikipedia.org'.