Warning: Table './internetbusiness/url_alias' is marked as crashed and last (automatic?) repair failed query: SELECT COUNT(pid) FROM url_alias in /home/content/43/3775343/html/includes/database.mysqli.inc on line 134
htaccess Lines for Multi-site Drupal Sites with Mobile Sub-Domains | Internet Business

Mobile Full Site Switcher

Powered by Drupal, an open source content management system
user warning: Table './internetbusiness/url_alias' is marked as crashed and last (automatic?) repair failed query: SELECT dst FROM url_alias WHERE dst = 'node/11765' in /home/content/43/3775343/html/sites/all/modules/globalredirect/globalredirect.module on line 138.

Internet Business

htaccess Lines for Multi-site Drupal Sites with Mobile Sub-Domains

The beauty of the Drupal mobile site configuration for which you can read here the introduction and step-by-step tutorial is that it is almost directly applicable to a multi-site set-up.

I refer here to a multi-site configuration in which several sites/domains share the same Drupal code-base, while each site has its own database. Here I assume that you know how to create a multi-site installation that works well.

Say that you have for example “n” sites running of the same code base, each with their own database, e.g. www.example1.com, www.example2.com till www.example”n”.com.

Now you use the multi site approach that we have explained in the tutorial to create the corresponding mobile sites m.example1.com, m.example2.com till m.example”n”.com.
 
You follow the exact same step-by-step approach as explained in the tutorial. The only change is that you use the extra htaccess lines that you get here as basis for the changes you make in the htaccess file.
 
You add the lines below (and as in the .txt file attached to this page) to your htaccess file before the “Boost” section.
 
Replace “example1.com”, “example2.com” and “example3.com” with your domain names. I assume that you see the logic in it and can make the changes as needed when you have more domains in the multi-site.
 
The code shows just the block that you would need to add to your htaccess if you have only mobile sites for www.example1.com and www.example2.com. If you want to create more mobile sites, study the logic in these lines and add also a block of lines for these sites to the htaccess.
 
 
This code is for 99% based on what I found here: Making a Boost Cached Site Mobile
 
The adaptations I have made is mainly adding left and right a $-sign and an extra line to make sure that www.example.com/xyz redirects to m.example.com/xyz and vice versa. And I added a few lines to make it work in a multi-site setting.
 
Note that I am no expert in htaccess code. There are probably lots of ways that this code can be simplified and improved. Your comments and ideas are welcome as comments below.

 

The Extra htaccess Lines for Mobile Sites in Drupal Multi-Site


 
 #Replace example1.com, example2.com and example3.com with your domains
 #Extra htaccess lines for mobile sites for www.example1.com and www.example2.com in a multi-site configuration
 
 #mobile site for www.example1.com
 #set cookie (in the client's browser)
 RewriteCond %{QUERY_STRING} ^(.*)device=desktop(.*)$
 RewriteCond %{QUERY_STRING} !^(.*)device=mobile(.*)$
 #there is also a mobile site for example2.com with the domain m.example2.com
 RewriteCond %{HTTP_HOST} !^www\.example2\.com
 RewriteCond %{HTTP_HOST} !^m\.example2\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteRule .* - [CO=mt_device:desktop:.example1.com:1440:/]
 
 #redirect to desktop site based on url or cookie
 # don't apply the rules if already in the desktop site, infinitive loop
 RewriteCond %{HTTP_HOST} !^www\.(.*)$
 #there is also a mobile site for example2.com with the domain m.example2.com
 RewriteCond %{HTTP_HOST} !^www\.example2\.com
 RewriteCond %{HTTP_HOST} !^m\.example2\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{HTTP_HOST} ^m\.example1\.com$ [NC]
 RewriteCond %{QUERY_STRING} ^(.*)device=desktop(.*)$ [OR]
 RewriteCond %{HTTP_COOKIE} mt_device=desktop
 RewriteRule ^(.*)$ http://www.example1.com/$1 [L,R=302]
 
 #no redirect to mobile when cookie=desktop and user agent is mobile
 RewriteCond %{HTTP_HOST} !^m\.(.*)$
 #there is also a mobile site for example2.com with the domain m.example2.com
 RewriteCond %{HTTP_HOST} !^www\.example2\.com
 #RewriteCond %{HTTP_HOST} !^m\.example2\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{QUERY_STRING} !^(.*)device=mobile(.*)$
 RewriteCond %{HTTP_COOKIE} mt_device=desktop
 #skip the next two rules
 RewriteRule .* - [S=2]
 
 #set cookie (in the client's browser)
 RewriteCond %{QUERY_STRING} ^(.*)device=mobile(.*)$
 RewriteCond %{QUERY_STRING} !^(.*)device=desktop(.*)$
 #there is also a mobile site for example2.com with the domain m.example2.com
 RewriteCond %{HTTP_HOST} !^www\.example2\.com
 RewriteCond %{HTTP_HOST} !^m\.example2\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteRule .* - [CO=mt_device:mobile:.example1.com:1440:/]
 
 #redirect to mobile site based on url, cookie or device type
 # don't apply the rules if already in the mobile site, infintine loop
 RewriteCond %{HTTP_HOST} !^m\.(.*)$
 #there is also a mobile site for example2.com with the domain m.example2.com
 RewriteCond %{HTTP_HOST} !^www\.example2\.com
 #RewriteCond %{HTTP_HOST} !^m\.example2\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{HTTP_HOST} ^www\.example1\.com$ [NC]
 RewriteCond %{QUERY_STRING} !^(.*)device=desktop(.*)$
 RewriteCond %{QUERY_STRING} ^(.*)device=mobile(.*)$ [OR]
 RewriteCond %{HTTP_COOKIE} mt_device=mobile [OR]
 RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipad|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
 RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini" [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
 #iPad user agent has "Mobile", but we treat it as desktop
 RewriteCond %{HTTP_USER_AGENT} !ipad [NC]
 #status code 301 would stop future switching between desktop/mobile bcs. browsers cache that status code
 RewriteRule ^(.*)$ http://m.example1.com/$1 [L,R=302]
 
 #mobile site for www.example2.com
 #set cookie (in the client's browser)
 RewriteCond %{QUERY_STRING} ^(.*)device=desktop(.*)$
 RewriteCond %{QUERY_STRING} !^(.*)device=mobile(.*)$
 #there is also a mobile site for example1.com with the domain m.example1.com
 RewriteCond %{HTTP_HOST} !^www\.example1\.com
 RewriteCond %{HTTP_HOST} !^m\.example1\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteRule .* - [CO=mt_device:desktop:.example2.com:1440:/]
 
 #redirect to desktop site based on url or cookie
 # don't apply the rules if already in the desktop site, infinitive loop
 RewriteCond %{HTTP_HOST} !^www\.(.*)$
 #there is also a mobile site for example1.com with the domain m.example1.com
 RewriteCond %{HTTP_HOST} !^www\.example1\.com
 RewriteCond %{HTTP_HOST} !^m\.example1\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{HTTP_HOST} ^m\.example2\.com$ [NC]
 RewriteCond %{QUERY_STRING} ^(.*)device=desktop(.*)$ [OR]
 RewriteCond %{HTTP_COOKIE} mt_device=desktop
 RewriteRule ^(.*)$ http://www.example2.com/$1 [L,R=302]
 
 #no redirect to mobile when cookie=desktop and user agent is mobile
 RewriteCond %{HTTP_HOST} !^m\.(.*)$
 #there is also a mobile site for example1.com with the domain m.example1.com
 RewriteCond %{HTTP_HOST} !^www\.example1\.com
 #RewriteCond %{HTTP_HOST} !^m\.example1\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{QUERY_STRING} !^(.*)device=mobile(.*)$
 RewriteCond %{HTTP_COOKIE} mt_device=desktop
 #skip the next two rules
 RewriteRule .* - [S=2]
 
 #set cookie (in the client's browser)
 RewriteCond %{QUERY_STRING} ^(.*)device=mobile(.*)$
 RewriteCond %{QUERY_STRING} !^(.*)device=desktop(.*)$
 #there is also a mobile site for example1.com with the domain m.example1.com
 RewriteCond %{HTTP_HOST} !^www\.example1\.com
 RewriteCond %{HTTP_HOST} !^m\.example1\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteRule .* - [CO=mt_device:mobile:.example2.com:1440:/]
 
 #redirect to mobile site based on url, cookie or device type
 # don't apply the rules if already in the mobile site, infinitive loop
 RewriteCond %{HTTP_HOST} !^m\.(.*)$
 #there is also a mobile site for example1.com with the domain m.example1.com
 RewriteCond %{HTTP_HOST} !^www\.example1\.com
 #RewriteCond %{HTTP_HOST} !^m\.example1\.com
 #there is no mobile site for example3.com
 RewriteCond %{HTTP_HOST} !^www\.example3\.com
 RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
 RewriteCond %{QUERY_STRING} !^(.*)device=desktop(.*)$
 RewriteCond %{QUERY_STRING} ^(.*)device=mobile(.*)$ [OR]
 RewriteCond %{HTTP_COOKIE} mt_device=mobile [OR]
 RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipad|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
 RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini" [NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
 RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
 #iPad user agent has "Mobile", but we treat it as desktop
 RewriteCond %{HTTP_USER_AGENT} !ipad [NC]
 #status code 301 would stop future switching between desktop/mobile bcs. browsers cache that status code
 RewriteRule ^(.*)$ http://m.example2.com/$1 [L,R=302]
 
 
AttachmentSize
extrahtaccesscodedrupalmobilemultisite.txt8.15 KB

Recent comments

User login

Navigation