Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- HELP! mobile site redirect loop somewhere


Slickbear - 6:40 am on Oct 22, 2011 (gmt 0)


Hi All

I have learned a few things about htaccess since my original post, so I thought I would share my most recent code which works for sub-domains and does not suffer from the endless loop & an added bonus of having a link on your mobi site that will give users the option to view the full desktop site.


#BEGIN Mobile Redirects

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
RewriteRule ^ - [CO=mredir:0:www.yourdomain.com]
RewriteCond %{HTTP_USER_AGENT} "BlackBerry|Mobile|Opera|Palm|Symbian|Android|iPhone|iPod|iPad" [NC]
RewriteCond %{HTTP_HOST} !^mobile\.
RewriteCond %{QUERY_STRING} !(^|&)noredirect=true(&|$)
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301,L]

#END Mobile Redirects


**Replace "yourdomain.com" with your domain. Put a link on your mobi site to your desktop site and append the following on the end: /?noredirect=true

e.g....yourdomain.com/?noredirect=true

A last point to consider is that you don't need 100's of different user agents in your code, the above should cover about 98% of handsets being used out there.

I hope this helps

Cheers


Thread source:: http://www.webmasterworld.com/apache/4333664.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com