Attempt to exclude URL from htaccess rule

I am trying to set up global mobile phone forwarding in my httpd.conf for all my sites on the server and only edit it once, compared to 92 times. All mobile sites are redirected to one location so that it is beautiful.

However, I want to exclude one specific URL from the redirect at all. Here is what I still have that does not work and causes 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 understand why it causes a redirect loop at this particular url? This is just a folder in this htaccess domain containing only RewriteEngine off and an index.php file with a header () redirect call.

+4
source share
1 answer

The variable %{REQUEST_URI} will never look like http://www.example.com/mobile , because it will never contain the protocol (bit "http: //") or host information ("www.example.com" part ". You only want the part of the URI:

 RewriteCond %{REQUEST_URI} !^/mobile 

If you also need to check the host name, you will need an additional condition:

 RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
+7
source

Source: https://habr.com/ru/post/1444719/


All Articles