禁用所选目录的htaccess

时间:2012-03-04 17:11:37

标签: .htaccess

我有一个htaccess代码如下所示:

RewriteEngine On
RewriteCond $1 !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule (.*) http://localhost/host/$1 [R=301,L]
RewriteRule ^([-\w]+)?/?([-\w]+)?/?([-\w]+)?/?$ index.php?seg1=$1&seg2=$2&seg3=$3

但它仍然读取administrator文件夹中的htaccess。代码不正确吗? 感谢。

1 个答案:

答案 0 :(得分:1)

RewriteCond语句仅适用于一个 RewriteRule

您需要为第二次重写规则重复RewriteCond(并使用REQUEST_URI):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule (.*) http://localhost/host/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule ^([-\w]+)?/?([-\w]+)?/?([-\w]+)?/?$ index.php?seg1=$1&seg2=$2&seg3=$3