View Full Version : .htaccess errorpages path problems

10-10-2011, 12:16 PM
Hi guys,

I have my .htaccess file in a subdirectory from the server root. I want to configure the server to use custom error pages. However, I can't seem to make it use the right path.

Following is my directory structure:

Root --> Folder1 --> .htaccess
Root --> Folder1 --> errors --> error.php

I want to make it so that the .htaccess knows that the 404 error page is located in errors --> error.php - thus avoid stating an absolute path.

This is what I've got in my htaccess:

ErrorDocument 404 ./errors/errors.php

However, whenever I go to a page that doesn't exist, all I get is a white page with the following text: ./errors/errors.php. The url doesn't change to the error pages url.

If I, for instance, change the path in the .htacces file to: /errors/errors.php (without a leading dot), I get the default error page displayed.

What do I do wrong? It seems like I've tried everything with the relative path thing.

10-12-2011, 06:25 PM
Nobody has a clue?

10-13-2011, 03:03 PM
ErrorDocument expects the path argument to be either a fully qualified URI, a path relative to root or a string. Since a value beginning with . is neither a path relative to root or a fully qualified URI, it assumes it's a string, hence the fact you get it output on the page. The /errors/errors.php value would look in the root directory for that path, which doesn't exist, so it would fall back to the server default.

You would need to set it as...


10-14-2011, 11:45 AM
Heres a extra tip:

Make sure you donít specify a full URL to your 404 page.
For example something like "http://www.example.com/404.html"
This will cause your server to return the wrong response code, and will actually make it seem like the page was found correctly.

If you specify the path to your file relative to the root, like "/404.html",
you wonít have these problems.

Itís also a good idea to add the code

<meta name="robots" content="noindex">
to the <head> section of your 404 page, so that search engine robots donít add it to their indexes.

Here is a list of some common HTTP error codes:

400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
410 Gone
500 Internal Server Error

Example use:

ErrorDocument <error_code> /<your_page>.html

11-06-2011, 04:41 PM
Caigs: Thank you for that explanation! I did not know that the url had to be relative to the root. I guess there's no way to automatically let the error page know if the path to it changes - for instance, if I move it one level up or down relative to the root?

Conware: Thank you for the additional details - got it covered! :thumbsup: