2017-06-13 100 views
0

我的.htaccess文件:htaccess的被拒绝访问的index.php作为目录索引

DirectoryIndex index.php 

order allow,deny 
<FilesMatch "^(index|testfile)\.php$"> 
Allow From All 
</FilesMatch> 

拒绝访问的网站的根,这通常会打开index.php文件。加载网站的唯一方法是去mysite.com/index.php而不是mysite.com如果我删除order它按预期工作,但现在该目录中的任何文件都可以访问。

如何配置htaccess拒绝除index.php之外的所有文件,但也允许导航到mysite.com而不是mysite.com/index.php?使用mod_rewrite

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> 

替代的解决方案

+0

的downvoters可以解释为什么? –

回答

1

你可以像下面这样做

DirectoryIndex index.php 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !\.(?:css|js|png|jpe?g|gif|ico|tiff)$ [NC] 
RewriteRule ^(?!(index|testfile)\.php). - [F,NC] 
+0

感谢您的帮助,它看起来像它仍然拒绝访问,除非我添加一个尾随的'/'的URL,任何方式呢? –

+0

当我在我的Apache上测试时,它允许'http:// localhost','http:// localhost/index.php'和'http:// localhost/testfile.php' – anubhava

+0

你也可以尝试我的备用解决方案 – anubhava