I'm trying to setup a global mobile redirect in my httpd.conf for all of my sites on the server and only have to edit it once, vs. 92 times. All sites mobile will redirect to one locate so that's fine.
However I want to exclude one particular URL from redirecting at all. Here's what I have so far that isn't working and causing a redirect loop:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*iphone|ipod|blackberry|android|sgh|sonyericsson|psp|mot|htc|lg|nokia|palm|treo|j2me|webos|smartphone|symbian.*$ [NC]
RewriteCond %{REQUEST_URI} !^http://www.example.com/mobile [NC]
RewriteRule ^(.*) http://www.example.com/mobile [R=302,L]
Can anyone figure out why it's causing a redirect loop on that particular url? It's just a folder on that domain with a .htaccess in it only containing RewriteEngine off
and an index.php file with a header() redirect call.
The %{REQUEST_URI}
variable will never look like http://www.example.com/mobile
, because it will never contain protocol (the "http://" bit) or host information (the "www.example.com"` part). You only want the URI part:
RewriteCond %{REQUEST_URI} !^/mobile
If you need to check the hostname as well, you need an additional condition:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With