Web Dev, Linux, WordPress & More

Create custom error pages using .htaccess

by eric on January 19th, 2007 in: LinuxWeb Design

If you’re running a site on Apache’s web server, you can easily create custom error pages using Apache’s .htaccess file.

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

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

Here’s what each piece does:

this command tells the Apache web server that this is the error document to use for this directory and all subdirectories unless otherwise specified.
404 (403 and 500)
the error code for which the document should be displayed.
myerrors/404.html (403.html and 500.html)
the document on your site that should be used if this error should occur. 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 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.

More info and tutorials on .htaccess are available at Apache’s Website.

technorati tags:, , ,

Leave a Reply

%d bloggers like this: