You can achieve a lot of things with a .htaccess-file. You can make your own custom 404-error pages, redirect pages, rewrite pages, block IP-adresses and more. In this first .htaccess tutorial, I will explain the custom error pages.
How to make a .htaccess file
A .htaccess file is very easy to make. I always use Notepad to modify it. But you have to pay attention when you save the file. .htaccess is the extension of the file, not the name. The file must no be for example .htaccess.txt but just .htaccess . The .htaccess file must be uploaded to your root folder to make everything work.
Custom 404-error page
It is not hard to make you own custom 404-error page with .htaccess. First make a new file. This will be your error page. For example call it 404.html and place it in your root directory. There are loads of articles about “the perfect 404-page”. Some things include: adding a search box so people can search the site for what they were looking for, adding a e-mail adress to contact the webmaster, etc. There are nice articles about this on A List Apart and Coding Horror. This is what you have to place in your .htaccess file in our example:
ErrorDocument 404 /404.html
This is only the 404 error, but there are loads of errors that you can make custom pages for. A list:
- 302 – Redirect
- 400 – Bad Request
- 401 – Authorization Required
- 402 – Payment Required
- 403 – Forbidden
- 404 – File Not Found
- 405 – Method Not Allowed
- 406 – Not Acceptable
- 407 – Proxy Authentication Required
- 408 – Request Time-out
- 409 – Conflict
- 410 – Gone
- 411 – Length Required
- 412 – Precondition Failed
- 413 – Request Entity Too Large
- 414 – Request-URI Too Large
- 415 – Unsupported Media Type
- 500 – Internal Server Error
- 501 – Method Not Implemented
- 502 – Bad Gateway
- 503 – Service Temporarily Unavailable
- 504 – Gateway Time-out
- 505 – HTTP Version Not Supported
I’ll write more .htaccess tutorials soon.
- BROWSE / IN TIMELINE
- « CSS Positioning
- » CSS Adjacent-Sibling Selector
- BROWSE / IN .htaccess Other
- « Welcome!
- » Redirecting with .htaccess
TRACKBACKS (1)
COMMENTS (4) / ADD YOUR OWN COMMENT
SPEAK / ADD YOUR COMMENT
Comments are moderated.