Apache、.htaccess:filematch匹配URI还是真实文件名?
这是关于Apache的,尤其是Apache、.htaccess:filematch匹配URI还是真实文件名?,apache,http,.htaccess,Apache,Http,.htaccess,这是关于Apache的,尤其是.htaccess指令 假设存在/index.htm 我希望有一个允许访问的文件白名单(仅限.htm),因此我提出了以下建议: Order deny,allow Deny from all <FilesMatch "\.htm$"> Allow from all </FilesMatch> 如果运气不好,那么[question#1b]我可以说FilesMatch在重写之前拒绝访问,还是我做错了什么 最后,我提出的唯一可行的解决方案是在F
.htaccess
指令
假设存在/index.htm
我希望有一个允许访问的文件白名单(仅限.htm
),因此我提出了以下建议:
Order deny,allow
Deny from all
<FilesMatch "\.htm$">
Allow from all
</FilesMatch>
如果运气不好,那么[question#1b]我可以说FilesMatch在重写之前拒绝访问,还是我做错了什么
最后,我提出的唯一可行的解决方案是在FileMatch的regexp中包含空字符串:
<FilesMatch "(^|\.htm)$">
[问题2]这真的是解决这个问题的最好办法,甚至是唯一办法吗?我在网上找不到我的解决方案,所以我担心我从一开始就做错了
谢谢大家! 关于您的主要问题和问题1a,文件匹配文件路径上的匹配,请使用LocationMatch匹配URL 这里记录了这一点: 您的问题1b,mod_rewrite可以在授权开始前重写,如下所述: 我不清楚为什么你的重写规则不起作用,但我通常会这样写:
RewriteRule ^/$ index.htm [L]
IIRC,因为在服务器url和文件夹中总是有“/”,但我可能在这一点上错了
RewriteRule ^/$ index.htm [L]