拒绝所有文件,但使用htaccess的索引/默认页面 [英] Deny all files, but index/default page with htaccess
问题描述
我想拒绝目录中的所有文件,但是拒绝index.php(作为默认页面)。
I would like to deny all files in a directory, but index.php (as being the default page).
该解决方案几乎可以正常工作:
This solutions works almost:
Deny from all
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
唯一的问题:'upload / index.php'现在可以访问,但是'/ upload /'不是。我该如何允许默认页面带有htaccess?
The only problem: 'upload/index.php' is now accessable, but '/upload/' isn't. How can I allow the default page with htaccess?
推荐答案
您的问题是,正如您可能已经意识到的那样,重新拒绝所有内容,然后允许使用URI'index.php',但不允许使用URI'/'-即使'/'被重定向到幕后的index.php,它仍然是不同的URI,因此
Your problem is, as you may have figured it out, that you're denying all the stuff, then allow the URI 'index.php', but not the URI '/' -- even though the '/' gets redirected to the index.php behind the scenes, it's still a different URI, and thus it should be allowed too.
最简单的方法是使用 FilesMatch 指令,例如:
The easiest way to do it is using the FilesMatch directive, like this:
order allow,deny
<FilesMatch "^(index\.php)?$">
allow from all
</FilesMatch>
正则表达式 ^(index\.php)?$
表示 index.php或什么都没有。
The regex ^(index\.php)?$
means "index.php or nothing".
这篇关于拒绝所有文件,但使用htaccess的索引/默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!