.htaccess否认所有 - > directoryindex不起作用(拒绝所有&白名单文件)

时间:2011-10-04 09:53:47

标签: apache .htaccess

我想拒绝访问服务器上的所有文件和目录,但我明确允许这些文件和目录。我怎么能用.htaccess做到这一点?为什么我的方法不起作用?我知道我必须允许.css,.jpg等。

DirectoryIndex index.html

Order Deny,Allow
Deny from all
Allow from 127.0.0.1

<Files index.html>
  order Allow,Deny
  Allow from all
</Files>

编辑:当我尝试访问index.html时,上面的.htaccess给了我一个“Forbidden”错误。为什么呢?

编辑:这似乎可以解决问题。我希望没有漏洞:

#Disallow everything
<filesmatch "\.+">
    Order Allow,Deny
    Deny from all
</filesmatch> 

#Allow index
<Files index.html>
  order Allow,Deny
  Allow from all
</Files>

#Allow peripheral files
<FilesMatch "\.(css|png|jpg|js|ico)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

1 个答案:

答案 0 :(得分:1)

IP地址:127.0.0.1可以访问您的服务器而其他人则无法访问 这部分:

<Files index.html>
  order Allow,Deny
  Allow from all
</Files>

为所有用户设置对index.html的访问权限,但请记住,因为您没有提及有关其他文件的任何内容,因为他们拥有默认访问属性。
例如,下面的代码允许文件:01.jpeg01.html或以xml结尾的任何内容。

 <FilesMatch      !"(01\.jpe?g|01\.html|xml)$"> 
  order Allow,Deny
  allow from 127.0.0.1


</FilesMatch>