Apache2: <Files> 不适用于重写替换



请考虑在Web根目录中使用此.htaccess

RewriteEngine on
RewriteBase /
RewriteRule "^pretty/(.*)" index.php?pretty=$1
Order Allow,Deny
Deny from all
<Files index.php>
Allow from all
</Files>

/pretty/sweet被正确重写为/index.php?pretty=sweet(禁用后半部分(。

但是,我得到了一个 403 禁止(启用了后半部分(

我假设首先应用 URL 替换,然后<Files index.php>将匹配替换的URL,允许访问。

我在这里遗漏或误解了什么,我该如何解决这个问题?

RewriteRuleAllow/Deny指令来自不同的Apache模块。它们的加载顺序可能与您在 .htaccess 中的顺序不同。

我建议你坚持这样mod_rewrite本身:

RewriteEngine on
RewriteBase /
RewriteRule ^pretty/(.*)$ index.php?pretty=$1 [L,QSA]
# block all files except some known files
RewriteCond %{REQUEST_URI} !(?:/|/index.php|.+.(?:js|css|jpe?g|png|gif))$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [F]

相关内容

最新更新