How to Set a Custom 404 Page With .htaccess

Create or Modify a Custom 404 Page via .htaccess

  1. Login to your cPanel.
  2. Under the Files section click on File Manager.
Set Custom 404 Page in .htaccess File Manager
  1. Navigate to the document root folder for the site.
  2. Click on Settings.
File Manager Settings
  1. Ensure Show Hidden Files is selected.
Show Hidden Files
  1. Then click Save.
  2. Right-click on the .htaccess file and select Edit.
Edit the .htaccess file
  1. If the .htaccess file didn’t exist in the previous step, click on the +File link on the top left, name the file .htaccess, and set the directory for creation to /public_html/ or the document root of your site.
Creating an .htaccess file
  1. You might have a text editor encoding dialog box pop-up, go ahead and just click Edit.
Edit File Encoding Option
  1. Now that you are ready to edit the .htaccess file, the simplest way to set a 404 error page is by directly setting a 404 error message in the .htaccess file itself:
  • ErrorDocument 404 “<H1>Page not found</H1>”
  1. If you already have a static HTML page that you’d like to use for 404 errors you can also directly point to that file with the .htaccess file as well. In this example, we have a 404.html page we want to serve up. Be sure to replace “404.html” with your actual page name:
  • ErrorDocument 404 /404.html
  1. After you’ve made your edits to the .htaccess file, click on Save Changes.
Saving .htaccess file
  1. You should see a green Success pop-up
  1. Now if you try to pull up a page that won’t exist on the server such as /ThisPageWon’tExist you should see the custom 404 error message that we’ve configured. This first image below is the default 404 error page when a custom one is not set:
Custom 404 Page
  1. The second one is the custom 404 page that we just created:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store