2013-01-23 34 views
0

我應該設置什麼規則,使mod_rewrite的忽略目錄「公衆」徹底?因此,我的意思是,文件應該可以在其中訪問,但如果文件不存在,服務器錯誤頁面應該會出現類似於FORBIDDEN或FILE NOT FOUND之類的東西。我不需要自定義錯誤頁面或類似的東西。我只是希望「公共」的行爲就像沒有mod_rewrite一樣。PHP國防部重寫的.htaccess忽略目錄

這裏是我的.htaccess文件:

RewriteEngine on 
RewriteCond $1 !^(index\.php|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

我的文件結構

/system/ 
/application/ 
/public/ 

我想要的文件夾公衆的行爲,像有設置完全沒有重寫規則,完全無視它。

編輯

這是我的.htaccess文件:

RewriteEngine on 

RewriteRule ^(public)($|/) - [L,NC] 

RewriteCond $1 !^(index\.php|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

我已經在/公/文件夾中有這樣的.htaccess:

RewriteEngine off 

我已經嘗試了所有的上面的不同答案(和谷歌一噸)。我試圖把他們混合在一起。

我的文件夾:

/system/ 
/application/ 
/public/ 
/public/.htaccess #RewriteEngine off 
/public/favicon.ico 
/index.php 

下面是與結果我得到的網址:

/public/favicon.ico -> I get the favicon 
/public/faviDon.ico -> I get the index.php (without mod rewrite you would get "not found") 
/public/ -> I get the index.php (without mod rewrite "forbidden") 

所以它仍然重寫URL,如果沒有找到該文件,或者在訪問文件夾直接。

你能瑟呢?

非常感謝你的努力的傢伙!對此,我真的非常感激!

+0

更適合serverfault.com – ethrbunny

+0

如果'public'是web根目錄,那麼''忽略'就你網站的網址而言。 – 2013-01-23 19:57:54

+0

檢查我的編輯請 –

回答

3

編輯我的機器上

我完全安裝文件

// /.htaccess 

RewriteEngine on 

RewriteRule ^(public)($|/) - [L,NC] 

RewriteCond $1 !^(index\.php|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

的.htaccess公用文件夾:

// /public/.htaccess 

Options -Indexes 
RewriteEngine off 

這將禁用重寫像你想要的。

/public/     -> 403 Forbidden 
/public/favicon.ico  -> 200 File found 
/public/not-existing.ext -> 404 File not found 

你有一個index.php在你的公共文件夾? 也許你可以刪除一個..

您的測試什麼樣的機器?

我測試了它在Linux的Apache + 2 + PHP5。3

我可以給你更多的支持,下午(我的時間+2 GMT)

EDIT 2

當我從/.htaccess還是刪除此行的工作

RewriteRule ^(public)($|/) - [L,NC] 

一切都由公用文件夾中的.htaccess處理。

也許這是您瀏覽器中的緩存問題。嘗試不同的瀏覽器/清理歷史記錄/安裝應用程序以刪除緩存..(取決於您使用的瀏覽器)

+0

一切正常,exept:訪問文件夾public /重定向到index.php(而不是FORBIDDEN)。訪問目錄中不存在的文件重定向到index.php(而不是FILE NOT FOUND) –

+0

我要瘋了在這個:( –

+0

+1,因爲是比我更好的解決方案。@maximkott你有index.php在'/ public /'中是否重定向到root index.php?如果是這樣,請給我看看你的.htaccess文件與渡輪的答案 – Peter