每當.php添加到url的末尾時,我試圖讓我的url重寫爲直接,但是當我包含註釋掉的部分時,本質上會出現錯誤。Apache mod-rewrite - hidding PHP
我可以得到的.php錯誤工作在它自己的,但沒有與所有其他規則。它是當前的形式,它使每個頁面錯誤。
所有其他部件正在工作。
該網站是設置這樣的錯誤去一個頁面 - error.php
Options -Indexes
RewriteEngine On
ErrorDocument 404 /error.php
ErrorDocument 301 /error.php
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
###### Send any requests for to error ######
RewriteRule ^index(\.[A-Za-z0-9-]+)/?$ error.php [R=404,NC,L]
###### changing Validate URL ########
RewriteRule ^validate/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/*?$ validate.php?$1=$2&$3=$4 [NC,L]
###### Show 404 error page when any request ends with '.php'
RewriteRule ^(.*)\.php(.?.*)$ error.php [R=404,NC,L]
# I also want to allow for anything that contains a get request here. but wanted to get the .php bit working first.
###### To remove the trailing slash ######
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
現在唯一的問題是,它似乎可以找到我定義的錯誤頁面。我得到與前面的例子相同的錯誤。我想知道如果我錯誤地指出了我的錯誤文檔「ErrorDocument 404/error.php」? – denski
當我提供第二條建議時,我會得到一個稍微不同的「內部服務器錯誤」。 '內部服務器錯誤 服務器遇到內部錯誤或配置錯誤,無法完成您的請求。 請通過webmaster @ localhost與服務器管理員聯繫,告知他們發生此錯誤的時間以及您在此錯誤發生前執行的操作。 有關此錯誤的更多信息可能在服務器錯誤日誌中可用。 此外,嘗試使用ErrorDocument來處理請求時遇到500內部服務器錯誤錯誤.' – denski
謝謝,它有95%,它將以.php結尾的所有內容重定向到錯誤。唯一的問題是,理想情況下,我希望它保持輸入的網址,例如'ex.com/test.php'而不是顯示'ex.com/error /'這可能嗎? – denski