Custom 404 page: Create error pages using htaccess

Creating a Custom 404 page is very important for SEO nowadays. First of all, for SEO purposes. Google increases the reputation of domains with their 404 error page correctly configured. The 404 error code means that one specific file on the server was not found. For example, you can use images, HTML font colors, and CSS styles in your error pages. This is a part of the HTTP protocol structure defined in RFC7231.

The advantages of having a properly configured not found error page:

  • It helps your visitors to guide for the correct place in your site
  • Google will increase your search engine rankings
  • It’s charming and modern

How the default raw 404 Not found error (without customization) looks like:

raw error message for 404 not found error

To have a custom 404 page for this error, we should edit our .htacess file, which is located under the root folder (usually inside the public_html folder for cPanel servers).

If you can’t find the .htacess file, you can simply create it.

Setting a custom 404 error message inside .htaccess

To set a custom html message, you should insert this line into .htaccess:

ErrorDocument 404 "<H1>Error 404</H1> My Custom Error 404 message goes here"

Now your error page will look like this:

404 error page

Setting the File Not found error to redirect to a specific error 404 custom page

You can create a specific custom 404 page to handle this error. In this example, we will create a file called 404.html , and place it in our root folder (usually public_html).

Now we should add this line to out .htaccess file:

ErrorDocument 404 /404.html

Now when opening a non-existent URL in the browser, you can see the contents of the just configured 404.html page:

custom 404 page working by htaccess

Common error pages can also be customized, such as 500, 401, 403

401 – Unauthorized – When your visitor tries to access a password-protected folder, without a valid login.

403 – Forbidden – When your visitor tries to access a URL without a valid file or folder permissions.

500 – Internal Server Error – Appears when having problems with cgi-bin scripts or permission issues.

To configure them, you should add these lines to your .htacess file:

ErrorDocument 500 /500.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html

This guide applies either for cPanel cheap web hosting servers and for dedicated servers running apache or a similar web server.

Conclusion

Customizing the error pages is a very important task nowadays, as Google considers this important for your website structure and SEO. You can configure an error 500 or a 404 custom page in every kind of site through the .htaccess file. Also, there are alternatives to configure a custom 404 page. For instance, by cPanel. You can have images, custom HTML font colors as well as custom HTML background colors in such pages.

Was this helpful?

Thanks for your feedback!

Gustavo Carvalho

Leave a Reply

Your email address will not be published. Required fields are marked *