2010-07-11 23 views
1

我對我的htaccess文件有一個小問題。目前,除了有人試圖訪問實際目錄時,它會將所有內容重定向回index.php進行處理。當目錄存在時,它會顯示403錯誤頁面,而不是像它假設的那樣重寫index.php的路徑。當通過互聯網訪問文件時,我可以修改哪些內容以使其始終保存在index.php中,但是仍然會在服務器上使用PHP加載正確的文件?在處理目錄之前重寫路徑?

Options -Indexes +FollowSymLinks 
RewriteEngine On 
RewriteBase/

ErrorDocument 403 /index.php?403 
ErrorDocument 404 /index.php?404 
ErrorDocument 414 /index.php?414 

RewriteCond %{HTTP_HOST} !^$ [NC] 
RewriteRule !^(.*) index.php [L] 

示例文件結構:

Web Directory 
- com 
- source 
- index.php 
- TEST.HTML 

如「COM」和源」的文件夾會顯示403,因爲用戶沒有訪問它們。 'index.php'和'TEST.HTML'等文件正常執行。我希望我的htaccess能將的所有內容重定向到index.php文件中,無論如何。

回答

1

我想你想要這個:

Options -Indexes +FollowSymLinks 
RewriteEngine On 
RewriteBase/

ErrorDocument 403 /index.php?403 
ErrorDocument 404 /index.php?404 
ErrorDocument 414 /index.php?414 

RewriteCond %{REQUEST_URI} !^/index.php 
RewriteRule .* index.php [L] 

這是對你不希望能夠直接訪問TEST.HTML,不想改變用戶的瀏覽器URL中的假設。如果其中任何一個假設都錯了,請告訴我,我將用適當的重寫信息更新答案。

+0

謝謝,你的例子幫助我意識到,我在我的重寫規則'RewriteRule!^(。*)index.php [L]'前面有否定。我不知道這個劇本有什麼奇怪的效果,「0或更多次沒有任何人物」。只需刪除'!'解決了這個問題。 – animuson 2010-07-11 07:17:07