我使用mod_rewrite运行一个CMS来pipe理漂亮的URL,但是我有另一个站点在CMS下面的一个子目录下运行,需要禁用URL重写,所以我在.htaccess文件中添加了几行代码:
Options -MultiViews Options +ExecCGI AddHandler php5-cgi .php Action php-cgi /cgi-bin/php-wrapper.cgi Action php5-cgi /cgi-bin/php-wrapper.cgi <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Added following two lines RewriteCond %{REQUEST_URI} ^/dir/ RewriteRule ^(.+) - [PT,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
这是有效的,但是/dir/下的其中一个目录是使用mod_auth保护的,并且仍然在被重写。 如果我在这个目录的.htaccess文件中取出Require valid-user指令,一切都很好。
这是受保护的目录中的.htaccess文件:
RewriteEngine off AuthType Basic AuthName "Administration" AuthUserFile "/home/user/admin/.htpasswd" require valid-user
任何帮助,将不胜感激。 这已经困扰了我几个星期! 我做了一些谷歌search和其他人有这个问题,但我还没有find一个解决scheme。
我也有同样的问题,迈克尔,终于find了解决办法
对于基本身份validation,服务器会写入“401 Unauthorized”标头,然后根据预定义的path查找错误文档。 大多数情况下,错误文档不会存在于您要保护的目录中,因此请求会被引发404错误的重写引擎处理。
解决这个问题非常简单。 您需要在您的.htaccess文件中添加一行代码,指示Apache忽略错误文档。 完成后,代码应该如下所示:
ErrorDocument 401 "Unauthorized Access" RewriteEngine off AuthType Basic AuthName "Administration" AuthUserFile "/home/user/admin/.htpasswd" require valid-user
希望这对你有用!
我会尝试将Rewrite语句放在下一个<DirectoryMatch>语句中。 你可以简单地用反逻辑来匹配每个目录,但不应该被重写的目录:
<DirectoryMatch "^/(?!dir)"> RewriteEngine on ... </DirectoryMatch>
Manni的替代scheme:
RewriteCond %{REQUEST_URI} !^/dir/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
并填写你添加的两个规则(假设我已经正确地理解了这个问题),并从受保护的.htaccess中删除RewriteEngine。