Custom 404 Page

I have made a custom 404 page at

I have edited my .htaccess file to send broken links to this page using the code widget here:

It all works great - except, I don’t know how to set the HTML status code of my 404 page correctly. It currently returns a 200 status code.

I have tried both:

<?php

header(“HTTP/1.0 404 Not Found”);

?>

AND

header($_SERVER[“SERVER_PROTOCOL”]." 404 Not Found");

In the 404 page header code, but still getting the 200 code returned. What am I doing wrong?

Best to add this to your htaccess file after you created the page

ErrorDocument 404 /yourpagename.html

1 Like

Thanks bourne

.htaccess already has that code on it, it works in that it redirects broken links to my 404 page - but I still get a 200 HTTP status and all the SEO scanning sites tell me that I don’t have a custom 404 page

Web design does my nut in

Ah got it

I have substituted

ErrorDocument 404 https://www.lasers.scot/404/

With

ErrorDocument 404 /404/

And it works perfectly - EDIT: thank you @bourne!

1 Like

I always thought it had to be .shtml for the 404 page if you are using cPanel. That isn’t an option in Blocs, so I am glad to hear this works, assuming you are using cPanel.

No - I’m editing the .htaccess file directly. It isn’t written by Blocs so can be coded in a text editor separately

Sure I’ve done that in the past but had difficulty getting it to work reliably using php error pages. Perhaps it was just the server, but I even had the web host try without luck, whereas pages set as shtml just worked and didn’t require any htaccess code.

I use both to be sure.

A really cool looking 404 mate. look at this one https://under-the-open-sky.com/404/ I find it to be pretty funny, I get the hidden message behind it.

1 Like

Just one note. If you are exporting page from blocs and you have called it 401, 40… page. Don’t forget to exclude them from site map :smiley:

2 Likes

No way to exclude the 404 page from the Blocs generated site map unless I edit it manually?

Yes. You need to do it manually. Before upload it to host
But when you export it once you can delete them from your project. Because normally the extensions is .shtml so you will not override ti next time when you upload your exported project to host.

Thank you. I have edited it manually and turned off auto sitemap so it won’t get overwritten

But my sitemap is sitemap.xml not .shtml?

error pages have the extensions .shtml :smiley: not sitemap :smiley:

I tried following the example above, but when I use:

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^liverupucams
RewriteRule (.
) https://liverupucams.com/1 [R=301,L] RewriteRule ^/?(.*).(html) /1 [R=301,L] RewriteCond %{REQUEST_FILENAME} ~-f RewriteCond ^(.*[^/]) /$1/ [L,R=301]
ErrorDocument 404 /404/

when you go to https://liverupucams.com/whatever it should redirect to the 404 error page and it just gives me a standard error:

Not Found
The requested URL was not found on this server.

Apache/2.4.29 (Ubuntu) Server at liverupucams.com Port 443

Can someone help me with this?