2011-10-04 74 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>