简体   繁体   English

尝试从htaccess规则中排除URL

[英]Trying to exclude a URL from htaccess rule

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. 我正在尝试在我的httpd.conf中为服务器上的所有站点设置全局移动重定向,只需编辑一次,而不是92次。 All sites mobile will redirect to one locate so that's fine. 移动所有网站将重定向到一个位置,这样就可以了。

However I want to exclude one particular URL from redirecting at all. 但是我想要从重定向中排除一个特定的URL。 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. 它只是该域上的一个文件夹,其中包含一个仅包含RewriteEngine off的.htaccess和一个带有header()重定向调用的index.php文件。

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). %{REQUEST_URI}变量永远不会http://www.example.com/mobile ,因为它永远不会包含协议(“http://”位)或主机信息(“www.example.com”) `部分)。 You only want the URI part : 只需要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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM