Custom 404 error page

For custom 404 error pages I’ve always used the .shtml extension when working with other design apps and I know this performs properly when somebody arrives at a non existent web page.

Given that Blocs only offers php or html in the page settings what is the best way of creating a custom 404 error page? I generally like to include a nice message, along with links to valid pages on the site.

3 Likes

Hey! did you ever figure out about this?

Yes. Create a page in Blocs called 404. This can be php or html

In the htaccess file write this line of code:

ErrorDocument 404 /404/

N.B I am using clean urls. You may have to add the extension to this code if you are not exporting that way.

2 Likes

something like this?

RewriteEngine On
ErrorDocument 404 https://volfly.net/error-404/

That’s not working. Try it like I suggested.

How do you actually do it? Cause yes it doesn’t work! I just add this code to my htaccess?

I did it like I said. Here is a screenshot.

Screenshot 2020-06-11 at 11.30.46

just realized im doing this wrong
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.)
RewriteRule ^.
$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Im doing it like this but website auditor keeps telling me I have no 404 page

That just looks like the code that sends pages to https versions. It shouldn’t be relevant in this case, but whatever works.

how can I check if it works?

Try going to a page that doesn’t exist on your website.

I get redirected to the main page!

That is probably down to that other https code with a wildcard * redirect. You have a lot going on with your website.

this is what I have

#php_flag display_startup_errors on
#php_flag display_errors on
#php_value error_reporting -1

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php?_url=/$1 [QSA,L] mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.)
RewriteRule ^.
$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

ErrorDocument 404 /404/

Just add the code to your .htaccess file as has already been suggested using the full path and file name. i.e.

ErrorDocument 404 /404.html

You could use any name for the error page, but 404.html seems to make sense.

Place the error page in the root of your domain.

TIP: if creating a 404 error page in blocs, it’s better to create it as a separate site and save it into a subfolder of your domain (eg error/yourdomain) You would then add the the path to the subfolder in your .htaccess file. eg

ErrorDocument 404 /error/404.html

This will enable you to upload the JS, CSS and images folder etc. into its own sub folder without it affecting the remainder of your site.

When checking, be sure to clear the browser cache and test by trying to access a non-existent page on your website.

1 Like

let me try this! I have another question for you! Im trying to stop google from indexing all the http. https:www or www from my site. Will like to only have https://yoursite.com. Do you know how to do it?

Redirect to the https:// version only and then tell them that is your preferred option inside the Google search console if you use that. Finally you could set up canonical links inside the page header area of Blocs that explicitly gives that https:// version.

yes but the problem is google indexed all version of my page www, http and https. So im trying to delete them and leave only https://site

Follow those steps and Google will eliminate the non https versions from their index over time.