Below are the Constraints,
- Lets assume we have two sites, one for Desktop(web version 'www.domain.com') and another for Mobile(mobile version 'mobile.domain.com').
- If i view my site from Desktop then Desktop version should appear, similarly if i view the same site from any mobile device then it should automatically redirected to Mobile site.
- Important constraint here is, user should be allowed to change their preference from desktop to Mobile version and vice-versa by the link provided in both the sites('Mobile version','Web version'). Based on the preference set by user, proper version should appear when user Re-visits the site.
- Moreover, if user is in 'web version' under search page, from here if user clicks 'Mobile version' then in Mobile site same search page with result should appear.
In your Web version site Vhost file:
RewriteCond %{REQUEST_URI} ^/switch_to_mobile
RewriteRule ^/switch_to_mobile$ - [co=version:mobile:.domain.com]
RewriteCond %{HTTP_REFERER} http:\/\/www.domain.com\/(.*)
RewriteRule ^/switch_to_mobile$ http://mobile.domain.com/%1 [R=302,L]
RewriteCond %{HTTP_COOKIE} version=mobile [NC]
RewriteRule ^(.+)$ http://mobile.domain.com$1 [L,R=302]
RewriteCond %{HTTP_USER_AGENT} BlackBerry
RewriteCond %{HTTP_COOKIE} !version=web
RewriteRule ^(.+)$ http://mobile.domain.com/$1 [R=302,L]
In your Mobile version site Vhost file:
RewriteCond %{REQUEST_URI} ^/switch_to_web
RewriteRule ^/switch_to_web$ - [co=version:web:.domain.com]
RewriteCond %{HTTP_REFERER} http:\/\/mobile.domain.com\/(.*)
RewriteRule ^/change_to_web$ http://www.domain.com/%1 [L,R=302]
RewriteCond %{HTTP_COOKIE} version=web [NC]
RewriteRule ^(.+)$ http://www.domain.com$1 [L,R=302]
(or) Even simpler you may try the below config
Web version:
RewriteCond %{REQUEST_URI} ^/change_to_mobile
RewriteCond %{HTTP_REFERER} http:\/\/www.domain.com\/(.*)
RewriteRule ^/change_to_mobile$ http://mobile.domain.com/%1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} iphone|ipod|alcatel|android|midp|240x320|blackberry|dopod|htc|huwai|lg|midp|nec|netfront|nokia|panasonic|portalmmm|sharp|sie-|sony|sonyericsson|symbian|benq|mda|mot-|motorola|palm|panasonic|philips|sagem|samsung|sanyo|sharp|sda|sgh-|t-mobile|vodafone|xda|pocket\ pc|opera\ mini|windows\ ce [NC]
RewriteCond %{HTTP_COOKIE} !preference=web [NC]
RewriteRule ^(.+)$ http://mobile.domain.com$1 [R=302,L]
Mobile version:
RewriteCond %{REQUEST_URI} ^/change_to_web$
RewriteRule ^/change_to_web$ "$0" [co=preference:web:.domain.com]
RewriteCond %{HTTP_REFERER} http://mobile.domain.com/(.*)
RewriteRule ^/change_to_web$ http://www.domain.com/%1 [R=302,L]
Hope above configuration should help you Guys !!!
2 comments:
Hi,
Thanks for this.
A quick question. If the mobile version and web version is running on separate servers and the cookie is set on the web version for the mobile preference, is that cookie readable from the server where mobile version is running?
thanks,
-ash
Ashly,
Cookie is meant for client side storage. So the cookie set on Web version is still readable from Mobile version server if domain is identical.
Thanks,
Vigram K
Post a Comment