Quantcast
Channel: IvyCat Web Services » tips and tricks
Viewing all articles
Browse latest Browse all 2

Creating Custom Error Pages Using .htaccess

$
0
0

How to create custom error pages by editing the .htaccess file:

First, edit an .htaccess file in your public_html directory so that it contains the following lines:

ErrorDocument 404 /myerrors/404.html
ErrorDocument 403 /myerrors/403.html
ErrorDocument 500 /myerrors/500.html

We’ll explain what each piece is:

  • ErrorDocument: This command tells Apache that this is the error document to use for this directory and all subdirectories, unless otherwise specified.
  • 404 (403 and 500): These represent the error code(s) for which Apache will serve custom error pages.  If you just want a custom 404 page, you only need the first line.
  • /myerrors/404.html (403.html and 500.html): The path to the document on your site that should be used when this error occurs. In this example, the error documents are located within the /public_html/myerrors/ directory. Please note that you need the / at the beginning so that the web server knows to start at /public_html/

If you use a path to the document like /myerrors/404.html, the URL in the browser will remain the same, but the error page is shown. If you wish to show the URL of the error page instead, simply use the complete URL to the error page. The example below shows how to do this for the 404 (file not found) error:

ErrorDocument 404 http://www.yourdomain.com/myerrors/404.html

If your error page doesn’t come up that after doing this, check spelling, capitalization, and the path or url of the error document to make sure it’s correct. If it is, try adding more content to the error page. Some browsers are set so that if there isn’t enough content in the error page, they use their own default error page.


Viewing all articles
Browse latest Browse all 2

Trending Articles