Apache Mobile Filter and Domain Access configuration (optional)
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
To get Apache Mobile Filter and Domain Access (or other similar domain-based modules like Boost) working together, do the following:
First, install Apache Mobile Filter at the server level.
Next, configure Domain accordingly. For this example, all we want is theme switching via url redirection at the web server level. We have a domain (example.com) pointing to ~/public_html and subdomain (m.example.com) pointing to the same directory ~/public_html. Using a basic setup with Domain Access, we can access the site at both http://example.com and http://m.example.com with theme switching working correctly. No redirection was in place.
Third, after finishing the last step of the AMF installation guide, append required code to your httpd.conf (or apache2.conf). For the site in this example, the following code was used:
# ApacheMobileFilter
#
#Configuration AMF Filter
#
PerlSetEnv AMFMobileHome /home/AMF
PerlSetEnv AMFProductionMode true
PerlTransHandler +Apache2::AMFLiteDetectionFilter
PerlSetEnv ForceTabletAsFullBrowser true
PerlSetEnv FullBrowserMobileAccessKey fullsite
Here, we are using the Lite Detection Filter, but WURFL is more robust, it has support for more devices (but slower with more overhead). Make sure to restart apache2 at this point. During the start-up, you should see initialization information for AMF. If you can't access your site at this point, something is incorrect with your AMF setup. Also added is the 'FullBrowserMobileAccessKey' which lets mobile users access the desktop site if they have the '?fullsite=true' query string appended to any URL.
Fourth (and finally), you need to do a little mod_rewrite work in your .htaccess file for the site in question. There are some good examples on the AMF mod_rewrite integration guide, but if you use the ones provided, you'll end up with an endless redirect loop (because the subdomain is pointing to the same location as the domain). Below is an example to prevent this from happening (place this code below the 'RewriteBase /' line in your .htaccess file).
# Make sure we don't redirect links from mobile to mobile infinitely
RewriteCond %{HTTP_HOST} !^m\.(.+)$ [NC]
# Use AMF to detect mobile devices and then redirect to mobile domain
RewriteCond %{ENV:AMF_DEVICE_IS_MOBILE} ^true
RewriteCond %{ENV:AMF_FORCE_TO_DESKTOP} !^true
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)$ [NC]
RewriteRule ^ http://m\.%2%{REQUEST_URI} [L,R=301]
All this is doing is redirecting you to 'm.example.com' if you are not already on that domain, are accessing via a mobile device and don't have the 'full site' query string set. This will also redirect any mobile requests from 'www.example.com' (with the www.) to 'm.example.com'.
At this point you should be able to access both domain and subdomain from your desktop. On a mobile device, you will be redirected to m.example.com.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion