2011-10-04 76 views
0

我想拒绝访问服务器上的所有文件和目录,但是我明确允许的几个文件和目录。我怎么用.htaccess来做到这一点?为什么我的方法不起作用?我知道我将不得不允许的CSS,JPG格式等.htaccess拒绝所有 - > directoryindex不起作用(拒绝所有白名单文件)

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> 

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

编辑:这似乎是伎俩。我希望没有留下孔:

#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> 
+0

第一条指令应该读取'。+“>'。 '“\。+”'只匹配包含点的文件,但不包含文件的文件是允许的。 – JayVee

回答

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>