Return to "Miscellaneous"A .htaccess is simply a text file that provides commands to control a web site. You can put your .htaccess in any directory and changes applied to the file will affect the directory it is placed in, as well as all sub-directories.
Below are some of the most common uses for a .htaccess file.
Custom Error Pages -The most common are the 404 (Not Found) and the 500 (Internal Server Error). To create a 404 error page you will enter the following line into your .htaccess file.
ErrorDocument 404 /errors/notfound.html
(This means that any error code resulting in 404 to be forward to yoursite.com/errors/notfound.html)
To create a 500 error page you would enter:
ErrorDocument 500 /errors/internalerror.html
You can name the pages anything you want, those are just examples.
Redirect - If you have made changes to your site and want to redirect visitors from your pages to your new one, you can use a redirect to have them forward automatically. You will enter the following into your .htaccess:
Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
Change your Default Directory Page - By default the index.html page is loaded first. If you have multiple index files, or you have named your index file differently, you can adjust this with the “DirectoryIndex” option. For example, you have named your start page “home.html”, then you would enter the following: (with your home page name listed first)
DirectoryIndex home.html index.html index.htm index.php
If you list other files names it will look for them in that order.
Important Note: Creating and editing .htaccess files should only be done by skilled users. You can cause your web site to go down if you make incorrect changes to your .htaccess file.