添加3个以上规则时,htaccess会显示错误500

时间:2015-03-04 15:23:18

标签: .htaccess mod-rewrite

这是我的htaccess:

Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^home index.php
RewriteRule  ^register register.php
RewriteRule  ^rules rules.php [L]

当我向htaccess添加第四条规则时,它返回500错误。 所以htaccess只允许3个重写规则?

1 个答案:

答案 0 :(得分:0)

首先,当您收到错误时,应始终检查Apache error_log文件。它将为您提供错误的具体原因。我们只会猜测你的问题可能是什么。

现在这可能不是"""但问题是RewriteCond仅适用于直接跟随它的RewriteRule。您不能对所有规则使用相同的条件。您还应该养成在规则上使用[L]标志的习惯,以防止它在匹配后读取下一个规则。

Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^home/?$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^register/?$ register.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^rules/?$ rules.php [L]