Create a custom 404 error page using htaccess

Creating a Custom 404 Not found error page is very important nowadays. First of all, for SEO purposes. Google increases the reputation of domains with their 404 error page correctly configured.

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 customize this error page, 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 error message inside .htaccess

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

Now your error page will look like this:

404 error page with an error message only

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

You can create a specific 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:

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

complete 404 error page by htaccess

Common error pages can also be configured, 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:

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

Leave a Reply

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