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.
我正在尝试在我的httpd.conf中为服务器上的所有站点设置全局移动重定向,只需编辑一次,而不是92次。移动所有网站将重定向到一个位置,这样就可以了。
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:
但是我想要从重定向中排除一个特定的URL。这是我到目前为止无法正常工作并导致重定向循环:
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.
任何人都可以弄清楚为什么它会导致该特定网址的重定向循环?它只是该域上的一个文件夹,其中包含一个仅包含RewriteEngine的.htaccess和一个带有header()重定向调用的index.php文件。
1 个解决方案
#1
7
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:
%{REQUEST_URI}变量永远不会像http://www.example.com/mobile,因为它永远不会包含协议(“http://”位)或主机信息(“www.example.com”) `部分)。您只需要URI部分:
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]
#1
7
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:
%{REQUEST_URI}变量永远不会像http://www.example.com/mobile,因为它永远不会包含协议(“http://”位)或主机信息(“www.example.com”) `部分)。您只需要URI部分:
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]