2012-08-24 39 views
3

我想拒絕目錄中的所有文件,但index.php(作爲默認頁面)。拒絕所有文件,但索引/默認頁與htaccess

此解決方案的工作方式幾乎:

Deny from all 
<Files index.php> 
    Order Allow,Deny 
    Allow from all 
</Files> 

唯一的問題: '上傳/的index.php' 是現在accessable,但 '/上傳/' 不是。我如何使用htaccess允許默認頁面?

回答

7

你的問題是,你可能已經想通了,那你拒絕所有的東西,然後讓URI人指數.php',但不是URI'/' - 儘管'/'在後臺被重定向到index.php,它仍然是一個不同的URI,因此它也應該被允許。

它使用的是FilesMatch指令,這樣做最簡單的方法:

order allow,deny 
<FilesMatch "^(index\.php)?$"> 
    allow from all 
</FilesMatch> 

正則表達式^(index\.php)?$指「的index.php或全無」。

0

你可以嘗試使用mod_rewrite,代替你有什麼用:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/(index.php)?$ 
RewriteRul^- [L,F] 
相關問題