请考虑在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,允许访问。
我在这里遗漏或误解了什么,我该如何解决这个问题?
RewriteRule
和Allow/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]