2017-05-27 60 views
1

的.htaccess問題我有下面的代碼的.htaccess裏面:與404和URL重寫

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ 404.php [L] 

這樣做的目的是爲了

  • 取下的.php擴展url

  • 重寫網址,以便POST數據將出現在斜槓後面,即如果原始網址爲website.com/sheet?username=bob,這將被改寫爲website.com/sheet/bob

  • 重定向到一個自定義的404頁面時給出了具體的網址沒有找到

,同時通過WAMP本地開發這個代碼執行罰款,我能看到基於website.com/sheet/<user><user>值的不同信息。

當我上傳更改到實時站點時,代碼不再有效,並且將website.com/sheet/bob顯示爲我的自定義404頁面。

是我的.htaccess錯?對不起,我很沒經驗.htaccess


編輯如果我刪除.htaccess,如果我試圖去website.com/sheet.php,我得到以下錯誤:

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 

More information about this error may be available in the server error log. 

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. 

但這產生error文件在我的文檔根目錄雖然,所以我不確定如何看到問題:s


謝謝

+0

如果您完全從服務器上刪除您的htaccess版本,服務器行爲是否有所不同?只是爲了檢查它是否真的是你使用的.htaccess。 – stevenvanc

+1

我刪除了'.htaccess',併發生了一個不同的問題。我在原始文章中添加了一個編輯(用於其他人的可見性) – Sej

+0

首先,您爲什麼要嘗試使用重寫來實現'ErrorDocument'指令的工作......? – CBroe

回答

0

這個問題似乎與.htaccess

原:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ 404.php [L] 

現在:

ErrorDocument 404 /404.php 

Options -Indexes -MultiViews 
RewriteEngine on 

RewriteCond %{THE_REQUEST} \.php [NC] 
RewriteRule ^(?!404\.php)$ - [L,NC,R=404] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^/]+)/?(.*)$ ./$1.php [L] 

我不是在.htaccess文件非常好,所以我coulnd't告訴你確切的問題是,但這種變化似乎完成我沒有給出任何錯誤,我的目標是什麼。