![]() |
htaccess redirect on mobile and desktop for subdomain
Hi,
I am trying to do the following in htaccess: www.example.com to m.example.com - on mobile (detect user agent) m.example.com to www.example.com - on desktop I got the first part of mobile redirect done but if I try to configure the second i get an unending loop. Here is my htaccess code: Code:
RewriteCond %{HTTP_USER_AGENT} android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]Shan-tal |
In part 2 you are saying if the host header starts example or m.example then redirect to www.example.com.
I'd ask this: Is the physical directory for www.example.com different to the physical directory where the .htaccess file is held? If it is different, but under the root where .htaccess file with the rule is held, it may be inheriting from the root .htaccess file. At one point in time the default behaviour was that an .htaccess in the root folder will affect all its subfolder, unless overwritten by subfolder-specific .htaccess files. However, that appears to have changed and inheritance is no longer the default behaviour. It is set by the directive RewriteOptions inherit | InheritBefore so check these are not set. If your redirect is into the same root directory you will have a loop. .htaccess runs every time the directory is entered. The 'last rule' stanza applies on a per iteration basis. Your host header is not rewritten by your rule - which forms you logic test - so the condition will always be true, taking you into a never ending loop. The fix is probably to direct into another directory. Depending on the access you have to the server, you can enable logging for mod_rewrite with something like this in the vhost declaration/httpd.conf: Code:
RewriteLogLevel 3Personally I would code for this in a scripting language like php or asp and just include it at the top of each page, rather than let mod_rewrite do it. It's a bit 'clunkly' for the job you are trying to do. |
| All times are GMT +1. The time now is 05:48 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.