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. Select the Document Root for: option.
  4. Ensure Show Hidden Files is selected.
  5. Then click Go.
  6. file-manager-hidden-files
     
  7. Right click on the .htaccess file and select Edit.
  8. file-manager-htaccess-edit
     
  9. 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.
  10. file-manager-htaccess-create
     
  11. You might have a text editor encoding dialog box pop-up, go ahead and just click Edit.
  12. file-manager-text-editor-encoding
     

    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>"

    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

  13. 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
  14. 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-browser404-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.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Support Center:
Email Address
Optional, but our team may contact you for more information.
Like this Article?

Comments

Post a comment
n/a Points
2014-04-10 2:48 am

i need htaccess to 404 page so i already putted this code

RewriteEngine onErrorDocument 404 /404.php

but this is not working.

i open ftp   after that i went /httpdocs   ....there are not puplic html folder

please guid me

Staff
5,587 Points
2014-04-10 4:02 am
Hello Rajkaran, and thanks for the comment.

If you have a /httpdocs directory instead of /public_html then that's fine. That should still be your website's document root where your website files go.

Are you able to access your 404 page directly in your web browser when going to it such as: http://example.com/404.php ?

If so, then at the top of your.htaccess file, you would just want to use this:

ErrorDocument 404 /404.php


You do not need to turn on the Apache RewriteEngine when using the ErrorDocument setting, so you don't need that part.

If your custom 404 page still isn't coming up, what happens when you try to access a page that doesn't exist? Do you get another specific error from the server? Are you running a CMS that might be handling 404 error pages internally?

Please let us know if that fixes your problem.

- Jacob
n/a Points
2014-04-10 7:51 am

hello sir

i got your reply but this is not running 404 page.....i am sending .htaccess file code...

//-----------.htaccess code---------------------------

RewriteEngine on

ErrorDocument 404 /404.php

 

//------------------end of code--------------------------

Staff
4,058 Points
2014-04-10 7:54 am
I see that you are referencing a file labeled 404.php within your .htaccess file. Have you named your file 404.php? If not, you will need to change this to the name of your file.
Staff
5,587 Points
2014-04-10 10:47 am
Hello again Rajkaran,

As I said in my previous comment, you do not need to turn on the Apache RewriteEngine. For your 404 page to function, place this on the very first line of your .htaccess file, at the very top:

ErrorDocument 404 /404.php


- Jacob

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

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

Write New!
Do you want to publish a tutorial to our support center?

News / Announcements

SSL Certficate Warnings
Updated 2014-04-14 11:34 am EST
Hits: 2163
Heartbleed 0-day OpenSSL security bug
Updated 2014-04-14 04:43 pm EST
Hits: 5550

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

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!