A Beginner Guide to Set Custom 404 Page for Your Site Using .htaccess

By | October 23, 2019

404 page is displayed when your site can not find a file in your site. Using a user-friendly 404 page can improve our site traffic. In this tutorial, we will introduce how to set up a custom 404 page for your site using .htaccess file.

Set Custom 404 Page for Your Site Using .htaccess

Open your .htaccess file

We usually can find this file in your site root path.

Set 404 content using .htaccess

If you only want to display some message for users when 404 error occurs, you can do like this:

ErrorDocument 404 "<H1>Page not found</H1>"

This code means you site will display ‘Page not found‘ for a user when he opens a page which is removed. Of course, you can edit this content by yourself.

Set 404 page using .htaccess

If you have create a 404 page, the name of which is ‘404.html’, you can set it as:

ErrorDocument 404 /404.html

Then when a user open a lost page, 404.html page will be displayed.

Notice: it is /404.html not 404.html. if you set code to:

ErrorDocument 404 404.html

The page will only display text: 404.html, not display the content of 404.html.

Leave a Reply