GePraxa GePraxa - 3 months ago 14
Apache Configuration Question

Error 404 when I put custom page with absolute path in .htaccess

This is my .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


if I enter:
http://localhost/usuarios/
everything is perfect, but when I enter
http://localhost/usuarios
shows me the error page because I remove the
/


When I remove the absolute path leaving
ErrorDocument 404 /error
i do not fault in any way, the problem is that i do not recognize the file error.tpl error without absolute path because this index is called to another folder.

Questions:


  1. Is there any way to save write 40 times
    ErrorDocument xxx
    http://localhost/user/error
    .

  2. I want to avoid getting and modify the route when climbing the
    project to the real server. That's why I would like to NOT use the
    full path.


Answer
  1. I'm not aware of any way to have one directive apply to multiple status codes. This answer also says that it's not possible.

  2. You can use local URLs as shown in the documentation (bold mine):

    The syntax of the ErrorDocument directive is:

    ErrorDocument <3-digit-code> <action>
    

    where the action will be treated as:

    1. A local URL to redirect to (if the action begins with a "/").
    2. An external URL to redirect to (if the action is a valid URL).
    3. Text to be displayed (if none of the above). The text must be wrapped in quotes (") if it consists of more than one word.

    The following example is also given:

    ErrorDocument 500 /cgi-bin/crash-recover
    

Finally, you ask in a comment

It would be correct to show only error page for states 4xx and 5xx or I'm wrong?

That's correct. That same page of documentation says

Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any 4xx or 5xx status.