Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom 404 error issues with Apache - the ErrorDocument is 404 as well

I am trying to create a custom 404 error for my website. I am testing this out using XAMPP on Windows.

My directory structure is as follows:

error\404page.html index.php .htaccess 

The content of my .htaccess file is:

ErrorDocument 404 error\404page.html 

This produces the following result:

alt text

However this is not working - is it something to do with the way the slashes are or how I should be referencing the error document?

site site documents reside in a in a sub folder of the web root if that makes any difference to how I should reference?

When I change the file to be

ErrorDocument 404 /error/404page.html 

I receive the following error message which isn't what is inside the html file I have linked - but it is different to what is listed above:

alt text

like image 372
Malachi Avatar asked Aug 03 '10 15:08

Malachi


People also ask

How do I fix error 404 in Apache?

Tutorial Apache - Redirect the error 404 using HTACCESSCreate an HTACCESS file on the website directory. Add the following lines to this configuration file. Configure the correct file permission. Restart the Apache service.

What is a 404 error Apache?

A 404 error page indicates that the page we are trying to access is not able to locate. It is also known as the File Not Found page. At Bobcares, we often get requests regarding Apache errors, as a part of our Server Management Services.


2 Answers

The ErrorDocument directive, when supplied a local URL path, expects the path to be fully qualified from the DocumentRoot. In your case, this means that the actual path to the ErrorDocument is

ErrorDocument 404 /JinPortfolio/error/404page.html 

When you corrected it in your second try, the reason you see that page instead is because http://localhost/error/404page.html doesn't exist, hence the bit about there being a 404 error in locating the error handling document.

like image 136
Tim Stone Avatar answered Sep 19 '22 05:09

Tim Stone


.htaccess files are disabled by default in Apache these days, due to performance issues. When .htaccess files are enabled, the web server must check for it on every hit in every subdirectory from where it resides.

Just figured it was important to note. If you want to turn on .htaccess files anyway, here's a link that explains it:

http://www.tildemark.com/enable-htaccess-on-apache/

like image 22
Teekin Avatar answered Sep 20 '22 05:09

Teekin