2016-09-05 19 views
0

這是我的.htaccess錯誤404,當我把自定義頁面以絕對路徑在.htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/?$ index.php?url=$1 [NC,L] 

ErrorDocument 100 http://localhost/user/error 
ErrorDocument 101 http://localhost/user/error 
ErrorDocument 200 http://localhost/user/error 
ErrorDocument 201 http://localhost/user/error 
ErrorDocument 202 http://localhost/user/error 
ErrorDocument 203 http://localhost/user/error 
ErrorDocument 204 http://localhost/user/error 
ErrorDocument 205 http://localhost/user/error 
ErrorDocument 206 http://localhost/user/error 
ErrorDocument 300 http://localhost/user/error 
ErrorDocument 301 http://localhost/user/error 
ErrorDocument 302 http://localhost/user/error 
ErrorDocument 303 http://localhost/user/error 
ErrorDocument 304 http://localhost/user/error 
ErrorDocument 305 http://localhost/user/error 
ErrorDocument 307 http://localhost/user/error 
ErrorDocument 400 http://localhost/user/error 
ErrorDocument 401 http://localhost/user/error 
ErrorDocument 402 http://localhost/user/error 
ErrorDocument 403 http://localhost/user/error 
ErrorDocument 404 http://localhost/user/error 
ErrorDocument 405 http://localhost/user/error 
ErrorDocument 406 http://localhost/user/error 
ErrorDocument 407 http://localhost/user/error 
ErrorDocument 408 http://localhost/user/error 
ErrorDocument 409 http://localhost/user/error 
ErrorDocument 410 http://localhost/user/error 
ErrorDocument 411 http://localhost/user/error 
ErrorDocument 412 http://localhost/user/error 
ErrorDocument 413 http://localhost/user/error 
ErrorDocument 414 http://localhost/user/error 
ErrorDocument 415 http://localhost/user/error 
ErrorDocument 416 http://localhost/user/error 
ErrorDocument 417 http://localhost/user/error 
ErrorDocument 500 http://localhost/user/error 
ErrorDocument 501 http://localhost/user/error 
ErrorDocument 502 http://localhost/user/error 
ErrorDocument 503 http://localhost/user/error 
ErrorDocument 504 http://localhost/user/error 
ErrorDocument 505 http://localhost/user/error 

如果我輸入:http://localhost/usuarios/一切都是完美的,但是當我進入我http://localhost/usuarios顯示錯誤頁面,因爲我刪除在/

當我刪除的絕對路徑離開ErrorDocument 404 /error我不以任何方式故障,問題是,我不無絕對路徑識別文件error.tpl錯誤,因爲該指數被稱爲另一個文件夾。

問題:

  1. 有沒有辦法救寫40倍ErrorDocument xxx http://localhost/user/error
  2. 我想避免在將 項目攀登到真實服務器時獲取和修改路線。這就是爲什麼我不想使用 完整路徑。
+1

你究竟想要做什麼?爲什麼你會爲[200(成功)範圍內的HTTP代碼](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success)包含'ErrorDocument'配置? – Chris

+0

@Chris Good只是可以設置的所有頁面的一個例子,您不想使用所有的Desir。主要問題是解決這兩個問題,第二個問題想知道是否有一種方法可以避免多次使用相同的URL(並不意味着您全部使用),我想知道您是否可以在文件中定義變量或作爲一名專業人士,他們可以節省很多行。 – GePraxa

+0

只顯示狀態4xx和5xx的錯誤頁面或我錯了是正確的? – GePraxa

回答

1
  1. 我不知道的任何方式有一個指令適用於多個狀態代碼。 This answer也說這是不可能的。

  2. 您可以使用本地URL如圖the documentation(粗體礦):

    ErrorDocument指令的語法是:

    ErrorDocument <3-digit-code> <action> 
    

    那裏的行動將被視爲:

    1. 要重定向到的本地URL(如果操作以「/」開頭)。
    2. 要重定向到的外部URL(如果操作是有效的URL)。
    3. 要顯示的文本(如果以上都不是)。文本必須被包裹在引號(「)如果它由多個單詞的

    下面的例子也給出:

    ErrorDocument 500 /cgi-bin/crash-recover 
    

最後,你在評論中提出

這是正確的只顯示狀態4xx和5xx的錯誤頁面,或者我錯了?

這是正確的。同一頁的文檔說

可以爲指定爲錯誤條件的任何HTTP狀態代碼(即任何4xx或5xx狀態)定義自定義的錯誤響應。

+0

非常感謝你的回答,讓我明白!我現在可以繼續... – GePraxa