Oleksandr Novik
Oleksandr Novik

Reputation: 738

.htaccess ErrorDocument 404 doesn't work on localhost

I'm trying to implement a 404 error page. I have this project structure:

+Project
+---index.html
+---404.html
+---.htaccess

My .htaccess contains this line: ErrorDocument 404 /404.html

but this URL doesn't show my 404.html page:

http://localhost:63342/Project/wrong.html

Instead, I get the default Opera 404 page: https://ibb.co/XsFq5nZ

Whereas, my 404.html page looks like this: https://ibb.co/ZX7XB1d

The response from wrong.html is this: https://ibb.co/mJ2KztK

What is the problem?

Upvotes: 1

Views: 1565

Answers (1)

MrWhite
MrWhite

Reputation: 45923

ErrorDocument 404 /404.html

http://localhost:63342/Project/wrong.html

It would seem you have not specified a root-relative URL-path. From your URL structure, it should be:

ErrorDocument 404 /Project/404.html

UPDATE:

Try resetting to the default Apache error document:

ErrorDocument 404 default

Test that and then add your custom error document:

ErrorDocument 404 default
ErrorDocument 404 /Project/404.html

Make sure your 404.html file contains enough content. Some browsers will default an error response if the response received from the server is too small.

Upvotes: 2

Related Questions