我的.htaccess文件:
DirectoryIndex index.php
order allow,deny
<FilesMatch "^(index|testfile)\.php$">
Allow From All
</FilesMatch>
拒绝访问站点root,这通常会打开index.php。加载网站的唯一方法是转到mysite.com/index.php
而不是mysite.com
如果我删除order
它按预期工作,但现在该目录中的所有文件都可以访问。
如何配置htaccess以拒绝除index.php
以外的所有文件,但也允许导航到mysite.com
而不是mysite.com/index.php
?
答案 0 :(得分:1)
你可以这样做:
DirectoryIndex index.php
order Deny,Allow
# deny everything except landing page
<FilesMatch ".">
Deny From All
</FilesMatch>
# allow index.php and testfile.php
<FilesMatch "^(index|testfile)\.php$">
Allow From All
</FilesMatch>
替代解决方案,使用mod_rewrite
:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(?:css|js|png|jpe?g|gif|ico|tiff)$ [NC]
RewriteRule ^(?!(index|testfile)\.php). - [F,NC]