2013-02-25 77 views
1

所以我有一個htaccess文件如下重寫:htaccess的重寫 - 404在現有文件

RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L] 

每當我試着去http://domain/index我收到了404,但是當我嘗試去http://domain/index.甚至一個不存在的頁面,如http://domain/a,重寫工作很好,index.php var_dump()是合適的值。

index.php中唯一的代碼是var_dump($_GET);,所以我知道這不是PHP的問題。

有人可以向我解釋我的重寫規則有什麼問題,並解釋如何解決它?

編輯: 我忘了我有錯誤記錄啓用。它一直保存到error.log的錯誤是:

[Sun Feb 24 21:01:18 2013] [error] [client 192.168.1.1] Negotiation: discovered file(s) matching request: /path/public_html/index (None could be negotiated). 
+0

你可以試試這個:'RewriteRule ^([^ /] +)/? index.php?page = $ 1 [L]',並且在該規則之前添加'RewriteCond%{REQUEST_URI!!index \ .php [NC]'''''' – 2013-02-25 06:10:19

+0

現在,頁面將「index.php」轉儲爲'$ _GET ['page']的值,而不管任何事情。/index還會提供404. – 2013-02-25 06:15:16

+0

使用[R,L],您可以在腳本中看到替換URL和'var_dump($ _ SERVER)'以查看所有服務器變量。 – 2013-02-25 06:17:43

回答

3

由錯誤,似乎MultiViews已啓用。

您可以在文件的頂部試試這個:

Options +FollowSymlinks -MultiViews

此外,我建議如下:

# Prevent loops 
RewriteCond %{REQUEST_URI} !index\.php [NC] 
RewriteRule ^([^/]+)/? index.php?page=$1 [L] 

多視圖爲Content Negotiation,最好的描述here

1

當啓用MultiViewsOptions +MultiViews)時,Content Negotiation模塊將查找與index匹配的文件,但.php文件不符合匹配條件,因此它會與None could be negotiated一起失敗。您可以添加.php處理與使用相匹配:

MultiviewsMatch Handlers Filters 

如記錄在MultiviewsMatch