InMotion Hosting Support Center

In this article we'll discuss setting up a custom 404 error page via a .htaccess file. This will allow you to set the message that visitors to your site receive when they request a page that doesn't exist on the server.

If you read our previous article about 404 error not found pages it was discussed that handling 404 errors dynamically can be problematic if done very frequently. If you're running WordPress on your website, you might want to think about installing the W3 Total Cache plugin which has the ability to serve static 404 errors for WordPress.

It's typically recommended to handle 404 errors with a custom static HTML 404 error page instead of handling them dynamically. If you don't already have one you can learn about creating a custom 404 error page, and if you're looking to add advanced functionality to your 404 error page you can even learn about using Google's custom 404 page widget.

The easiest way to modify your .htaccess file would be using cPanel's file manager with the instructions below, although you can also upload a .htaccess file via FTP as well.

Modifying or creating a .htaccess via cPanel's file manager

  1. Login to your cPanel.
  2. Under the Files section click on File Manager.
  3. Navigate to the document root folder for the site.
  4. Click on Settings.
  5. Ensure Show Hidden Files is selected.
  6. Then click Save.
  7. Right click on the .htaccess file and select Edit.
  8. If the .htaccess file didn't exist in the previous step, click on New File at the top left, name the file .htaccess, and set the directory for creation to /public_html/ or the document root of your site.
  9. You might have a text editor encoding dialog box pop-up, go ahead and just click Edit.
  10. 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 "

    Page not found

    "

    If you already have a static HTML page that you'd like to use for 404 errors you can also direcly point to that file with the .htaccess file as well:

    ErrorDocument 404 /404.html

  11. After you've made your edits, click on Save Changes, and you should see a green Success pop-up.
    file-manager-text-editor-savefile-manager-text-editor-save-success
  12. 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. The first image below is the default 404 error page when a custom one is not set, and on the second one is our custom one that we've just created:
    404-default-error-in-browser
    404-custom-error-in-browser

You should now understand how to control how 404 errors are handled for your website, by either setting the error directly, or pointing to a custom 404 error page. If you need help on actually creating your custom 404 error page you would want to review our article on creating a custom 404 error page.

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

   
Social Login Joomla

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2017-02-03 3:50 pm

GREAT !GREAT !GREAT !GREAT !GREAT !GREAT !GREAT ! THANKS A TON GOD BLESS YOU.

It worked at one shot ! :-)

Staff
2,858 Points
2017-02-03 4:41 pm
Ashish, we're so happy to help! ^_^
n/a Points
2017-02-09 3:36 am

Hi,

I need a help i have a page like www.example.com/dwdwef it shows blank screen i want to redirect it to 404 page plz help me out.

Staff
29,997 Points
2017-02-09 4:00 pm
I recommend creating a 301 redirect from " www.example.com/dwdwef " to the "404.html" page.

Thank you,
John-Paul
n/a Points
2017-03-07 11:28 am

Thanks man, it worked! :)

n/a Points
2017-03-08 7:37 am

Thanks you very much. Simple and easy to follow

n/a Points
2017-03-16 2:52 pm

But what if you just want "not found" pages to redirect to home page?

Staff
29,997 Points
2017-03-16 6:06 pm
Here is a link to a helpful guide I found via online search where they discuss possible solutions.

Thank you,
John-Paul
n/a Points
2017-03-29 5:59 pm

Wow, how easy and simple! Thanks!

n/a Points
2017-06-08 5:43 pm

Hi there,

Is there a way to set 404 Redirects for specific pages? For example a 404 happening on: http://www.mywebsite.com/blog/invalid-slug should be redirected to http://www.mywebsite.com/blog and a 404 happening on http://www.mywebsite.com/company/invalid-slug should be redirected to http://www.mywebsite.com/company? Is the best way to do this via .htaccess or elsewhere?

 

Thanks

Basia

Staff
29,997 Points
2017-06-08 6:08 pm
You should be able to accomplish this with 2 separate .htaccess files. They discuss this further in this forum post I found via online search.

Thank you,
John-Paul
n/a Points
2017-06-30 1:39 am

This works fine for non-existing files but what about when a user tries to access a directory/folder which doesn't exist? How to do that setting in .htaccess file?

Staff
39,945 Points
2017-06-30 7:28 am
Hello Usering,

The same instructions still apply. You would just need to adjust the path specified. By default, all files and folders will be under a root directory.

If you have any further questions, please let us know.

Kindest regards,
Arnel C.
n/a Points
2017-07-09 10:39 am

Thank you! Worked first try!

n/a Points
2017-08-18 7:59 am

thanks for the information

n/a Points
2017-09-30 11:35 am

I do not have the option to show hidden files under Settings.  The only option is "Disable Character Encoding Verification Dialogs".

Staff
39,945 Points
2017-10-02 10:46 am
This is not a setting under how to set 404 via .htaccess. Please keep your comments in the appropriate article. See How to show hidden files (htaccess) when using cPanel's File Manager.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

17 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!