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

Support Center Login

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

9,968 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: ?

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-05-21 9:17 am

Thanks all of for helping.... realy this article very helpfull for me.

n/a Points
2014-08-08 12:12 pm

Hi also had the same problem

Create the .htaccess file on cPanel it easy than through FTP

19,030 Points
2014-08-08 12:30 pm

Thank you for your comment. Here is a link to our guide on Creating a file, it explains how to create a file in File Manager and FTP.

If you have any further questions, feel free to post them below.
Thank you,

n/a Points
2014-08-26 1:45 am

File Manager or Legacy File Manager

30,216 Points
2014-08-26 8:53 am
Hello Ron,

I am not sure what you are asking. Were you referring to John-Paul's link on making a file in the File Manager? The steps would be the same in Legacy File Manager, but the interface would appear differently.

Kindest Regards,
Scott M
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--------------------------

11,186 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.
9,968 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

n/a Points
2014-04-24 2:38 am

Hello sir

this is my website ....actualy have a problem if i put then genrate errors "The connection was reset" and if i enter on navigation bar then good...

i have htaccess there are some code:

# -FrontPage-
RewriteEngine On
RewriteCond %{HTTP_HOST} !^bhopalmpproperty\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
order deny,allow
deny from all
AuthUserFile /home/bhopalmp/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/bhopalmp/public_html/_vti_pvt/service.grp
please help me whats problem.....why not runing if i insert www
11,186 Points
2014-04-24 8:22 am
When visiting both and, I was unable to produce any errors on your site. It looks like the issue is solely isolated to your specific connection or browser. I recommend clearing your browser cache as there may be something in there that is causing the issue.
n/a Points
2014-05-20 3:11 am

hi how can i redirect subdomain files to 404 error

for eg: 


11,186 Points
2014-05-20 8:42 am
To clarify, are you referring to redirecting the entire subdomain to a 404 error? Are you referring to just 404s for the subdomain going to a specific 404 page?
n/a Points
2014-05-21 8:12 am

it worked :) 

thanks a million  @jeffma

n/a Points
2014-05-22 12:28 am

thanks !!

that worked 

n/a Points
2014-05-27 12:28 am

We are getting 404 not found error intermittenly in all the pages of site, but when i do refresh i am getting the page.

1. is it a webserver issue or a load balancer issue? the direct apache instance URL is working well.

2. is there a way we can refresh automatically ( 3 Retrys) whenever the we get 404 notfound issue ?

3. What Rewrite engine will do?

Please provide your inputs.

11,186 Points
2014-05-27 8:45 am
It sounds like you're using a non-standard setup. Could you clarify a bit more about your server configuration?
n/a Points
2014-06-09 3:39 pm

thanks... this was so helpful

n/a Points
2014-06-10 1:09 am

Hi guys

I am using insert query and also using mysql_insert_id() function but it is not giving response why i used oops..if i use simple query then its working but if i do through oops then not working....

$query=mysql_query("insert into table name (id,name,status) values('','test',1)");


now working but if i use this

$obj=new Model;




its not working...i know you are confuss but simply unserstand if i do through oops then mysql_insert_id() not workind why?

11,186 Points
2014-06-10 8:18 am
It looks like you are calling the mysql_insert_id() function but are not actually doing anything with it. Is this your complete code?
n/a Points
2014-06-10 9:26 am

yes this is not full code of .....

Now this is full code

if (empty($app->errors)) 


$tbl=new Model;





//--------------------- check duplicate records ---------------------------------


$sSql=" where city_title=? and city_cid=? and city_sid=? ";

$Category= $tbl->checkduplicatrecord($sSql, array($_REQUEST["city_title"],$_REQUEST["city_cid"],$_REQUEST['city_sid']));



$sSql=" where city_title=? and city_cid=? and city_sid=? and city_id<>?";

$Category = $tbl->checkduplicatrecord($sSql, array($_REQUEST["city_title"],$_REQUEST["city_cid"],$_REQUEST['city_sid'],$nId));















        echo mysql_insert_id();


//echo $tbl->_sqlQuery;



$error_msg="City Successfully Added";





$error_msg="City already exists";






11,186 Points
2014-06-10 9:38 am
It doesn't appear that you are running the INSERT MySQL command before you call the mysql_insert_id(); function which is causing no data to be displayed.
n/a Points
2014-06-10 9:43 am

thnx for guidance 

thank JeffMa :)

n/a Points
2014-06-11 1:30 am


i am beginer of smtp email,i used this smtp code an others on landing page there is working but if i use same code an other then genrate this error " SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. "

can you please help me.

i am using this code






if(isset($_REQUEST['yourname']) && $_REQUEST['yourname']!="")


$to  = ',,,,,' . ', '; // note the comma


// subject

$subject = "PPC Adword Enquiry";


// message

$message = '



  <title>enquiry </title>



<table width="100%" border="0" cellpadding="2" cellspacing="2">


    <td colspan="2">Candidate Information as below:-</td>



    <td valign="top" style="width:90px;">Interest :-</td>

    <td valign="top">'.$_REQUEST['interest'].'</td>



    <td valign="top" style="width:90px;">Name:-</td>

    <td valign="top">'.$_REQUEST['yourname'].'</td>



    <td valign="top" style="width:90px;">Email Address:-</td>

    <td valign="top">'.$_REQUEST['youremail'].'</td>



    <td valign="top" style="width:90px;">Contact No.:-</td>

    <td valign="top">'.$_REQUEST['yourphone'].'</td>



    <td valign="top" style="width:90px;">City  :- </td>

    <td valign="top">'.$_REQUEST['city'].'</td>



    <td valign="top" style="width:90px;">Message :-</td>

    <td valign="top">'.$_REQUEST['maintext'].'</td>



    <td valign="top" style="width:180px; float:right;">Visit Web Page          <a href="/support/" target="_blank">Click here</a></td>









$mail = new PHPMailer();

//$mail->SMTPSecure    = 'ssl';


$mail->Host = 'ssl://';

$mail->Port = 465;

$mail->IsSMTP(); // send via SMTP

//IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "";//""; //  "";// SMTP username

$mail->Password = "newmoon";//"bspartners_"; // "Year2013!";// SMTP password

$webmaster_email= ""; //Reply to this email ID


$name=''; // Recipient's name 

$mail->From = $name;

$mail->FromName = "PIMR INSTITUTE";

//echo $message;//$mail->AddAddress($email,'');











$mail->WordWrap = 50; // set word wrap


//echo $subject;exit; 

$mail->IsHTML(true); // send as HTML

$mail->Subject = $subject;

$mail->Body    = $message; //HTML Body

//$mail->$SMTPDebug = true;

if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; }

else               { echo "Message has been sent"; }



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



11,186 Points
2014-06-11 7:56 am
I noticed that you had the following line defined as the host:

$mail->Host = 'ssl://';

You do not need the ssl:// before the host name. Remove it and it should connect just fine.
n/a Points
2014-07-07 2:11 am

public_html/.htaccess (I go this file edit)

But show this code...


RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php


I now how to put 404.html code....


9,968 Points
2014-07-07 3:19 am
Hello Minura,

You should be able to use this at the top of your .htaccess file:

ErrorDocument 404 /404.html

That code that you have looks a bit off, typically you'd see it written as:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Because the RewriteCond %{REQUEST_FILENAME} !-f line is saying if the physical file doesn't exist proceed to the RewriteRule. However if you requested test.php and that script didn't physically exist, you wouldn't want to then use this:

RewriteRule ^(.*)$ $1.php

As that would tell the server, I know test.php doesn't exist, but go ahead now and try to load test.php and you would get stuck in a redirect loop.

Most CMS applications will have you redirect all missing URLs to a index.php script or similar to process the page not found error themselves. So it depends on what application you're using as to how exactly you would need things setup in your case.

- Jacob
n/a Points
2014-07-08 8:12 am

I have w3 total cache but I don't think it's working because you guys keep emailing me about usage issues with my 404 error pages.  I still have w3 cache enabled and configured according to your directions.  I also hadded the static 404 error code you mention in this post and it's not showing up.  Not sure what the solution is.

30,216 Points
2014-07-08 8:43 am
Hello sheresed,

Setting up the static 404 page as shown in the article should work for you. Please check to make sure you have done that all correctly. Also, be sure to place the code in the .htaccess file at the top so that no other code will run before it in the case of a 404.

Kindest Regards,
Scott M
n/a Points
2014-07-08 8:50 am

I did.  my site is  Maybe I missed something but I have the code at the very top.

30,216 Points
2014-07-08 10:16 am
Hello sheresed,

I did take a look at your site and it seems there is something else interfering. The code is correct and in the right place. Even without all other code in the .htaccess file it behaves the same way. I went to my own site as a test and installed Total Cache and I still was able to get it to work as described. It is likely a theme or plugin that is causing the interference. As a test, you may want to switch to another theme and see if it works then. If not, then it may be a plugin. You would want to turn them all off and see if it works then. If so, then enable them one by one and test in between. Once you enable the offending plugin the 404 redirect will break. Then you can decide which feature is better to keep, the plugin or the 404. To have the 404 you will likely need to get rid of that plugin.

Kindest Regards,
Scott M
n/a Points
2014-08-08 12:15 pm
Man you just nailed it in the head,been struggling with this and i'm sorted after bumping into your post.
My hosting company were not able to help me on this.
Thanks a milli.
n/a Points
2014-09-02 11:40 am
Introduce "your cPanel"
19,030 Points
2014-09-05 3:40 pm
Hello Virgil,

Thank you for contacting us today. If you are interested in learning about cPanel, see our guide titled What is cPanel.

Thank you,

n/a Points
2014-09-08 5:09 am

great stuff. Thanks

n/a Points
2014-09-27 2:36 am

we have problem with our domain, that is we can send a mail from other domain, but we are not able to send a mail with our domain. it showing error like this...

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() inC:\Inetpub\vhosts\\httpdocs\form.php on line 55

30,216 Points
2014-09-28 8:41 am
Hello Pallavi,

This is not the correct article for this type of question, you may want to create a new question as this is for discussion on setting a 404 page.

To get you started, however, do you have mail services set up on your local machine? The form is looking for 'localhost' which means it expects to use whatever machine the script is running from.

Again, please reply with a new question.

Kindest Regards,
Scott M
n/a Points
2014-10-02 11:25 am
thanks alot
n/a Points
2014-11-02 4:20 pm
It's good enough :-)
n/a Points
2014-12-01 12:15 pm
Placing a translator on top
n/a Points
2014-12-16 5:52 am

Its not working for me.

I created .htaccess and added. (using AWS)

ErrorDocument 404 /404page.html

n/a Points
2014-12-25 6:24 am

Thanks for your information. It's very useful to me

5,833 Points
2014-12-26 10:20 am
Hello Veera,

I am glad that you found the article helpful. Please let us know if you ever have any questions.

Kindest Regards,
TJ Edens
n/a Points
2015-01-20 9:53 am

thanks it worked - I am just wondering if you are better to set up an Error page 404 or is it simply fine to just redirect people to the main index ? Or does Google look on one of these better for SEO ? I am sure most people would happily be sent to my main index page rather than a 404 redirect page.


11,186 Points
2015-01-20 9:57 am
The choice is all up to you, but typically you want to direct them to a 404 page if there is not relevant content to direct them to. If there is relevant content to direct them so, such as a page is now located elsewhere, you may simply want to redirect them there.
n/a Points
2015-02-23 1:19 pm

Hello! First of all, thanks for the great article, it was really helpful!

The thing is that when I try to pull up a page that won't exist on the server (such as /ThisPageWon'tExist), I can only see a default "Page was not found" page, NOT the "404.html" I created. Can you tell me how can I edit that default page(I've tried to find the file in the file manager=no luck), or what should I do, so whenever someone tries to access a page that won't exist, the only thing they will be able to see is the "404.html" page(not that default page)?

30,216 Points
2015-02-23 5:09 pm
Hello Nina,

Did you follow all of the instructions above? The news 404 page will definitely need to exist in your account to display. It should be located in the public_html folder if you used this article as the example.

Kindest Regards,
Scott M
n/a Points
2015-03-06 2:35 am
Great, this work's for me. Thankyou so much Brother Jacob..!! :)
n/a Points
2015-03-09 7:44 pm

Hey im just curious in my .hcaccess file i have the code for my 401-500 pages likes so;

//Custom 404 errorsErrorDocument 401 /public_html/ErrorPages/404.html


because my error pages are in a seperate folder to my website how would i do this ?

the files are located in public_html/ErrorPages/404.html

30,216 Points
2015-03-10 10:45 am
Hello Dominic,

As long as you enter the correct path in the instructions above, then it will work the same as if the page was in the home directory.

Kindest Regards,
Scott M
n/a Points
2015-03-31 10:10 am
It is really useful article have explained it in a easy way. I need a full documentation of .htaccess file , means what can I with .htaccess file..
Thank you so much ..
19,030 Points
2015-04-06 9:15 am
Hello pritam,

Thank you for contacting us today. Please see our .htaccess section, it includes many guide on the subject.

Thank you,
n/a Points
2015-04-11 6:29 am

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhostApache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.19 i found that error..after creating my 404.php file and i also wrote ErrorDocument 404 /404.php..Help to solve that problem..where i put my 404.php file in localhost system  
30,216 Points
2015-04-13 9:45 am
You can place the file anywhere you want, but just need to address the path in the htaccess file if it is any deeper than the public_html folder. Typically, the file is just placed within the public_html folder.
n/a Points
2015-06-10 10:00 pm

Thank you so much for this page. I have been plagued recently by people linking to my site with broken links that were shown to me by Google wemaster toois. Thanks to what I read here, I followed the instructions and used the .htacces file to fix them all to It works! Thank you so much.

n/a Points
2015-08-06 8:32 am

hi my ftp page not acess other network site


19,030 Points
2015-08-06 3:38 pm
Hello Rajesh,

Thank you for contacting us. Unfortunately, it is not clear what you are asking. Please provide more details on what you are trying to accomplish.

Thank you,

Post a Comment

Email Address:
Phone Number:

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

62 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


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:
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!