This article will help you understand and build your knowledge of the .htaccess file you see when you run an Apache Web Server like ours.
Note: Article is still under editing
What is a .htaccess file?
It is Apache's directory-level configuration file (as opposed to httpd.conf, which is the main server configuration file) that provides the governing rules of how a web server should be ran/behave. When it is placed in a particular directory, the rules in it apply to that directory and all the subdirectories thereof.
Here is a good tutorial to the use and configuration of the .htaccess file.
What is a .htpasswd file?
The .htpasswd file is a file used to store usernames and passwords for protected areas of a website that use the .htaccess Protection.
Usage and Commands
Here are some examples as to how they can be used.
Change the Default Directory Index File
It can be used to chnage the default index file which is normally index.html, index.ext... to anything like foo.ext or whatever name/extension you prefer. To do this, use: <pre>DirectoryIndex foo.ext home.html home.php foo.php</pre>
Customizing Error Handling/Error Pages
If you have ever wondered how people chnage their 404, 500... error pages to something like lost.ext, then you will like this code in your .htaccess file: <pre> <nowiki> ErrorDocument [Error Number] [Error Document] Error Document 404 /404.html </nowiki> </pre> Where [Error Number] is replaced with the error number, and [Error Document] is replaced with the path fo the error document which can be internal or external as in: <pre>http://www.anothersite.com/foo.ext or /foo.ext</pre>
Server Generated URL Redirects
You moved or renamed a directory and you know people still have the old directory bookmarked so you want them to be redirected to the new directory, then you can use this code: <pre>Redirect [Trigger] [New Destination] Redirect /old http://www.url.com/new Redirect /old /new</pre>
Limiting Access by Hostname/IP Address
Use this section of this article if you are intrested in blocking access to a file/folder on your server: <pre> <Files admin.cgi>
order deny, allow deny from ALL allow from 184.108.40.206
</Files> </pre> This example denies access to admin.cgi to everyone but the owner of the IP Address mention in 220.127.116.11. You can also use this for a folder, in that case you would replace admin.cgi with the name of the folder. If you are intrested in using the Hostname rather than the IP then use: <pre> <Files admin.cgi>
order deny, allow deny from ALL allow from mymachine.networkdomain.com
</Files> </pre> You can also use it for your whole network to have access to it alone, example: <pre>
- IP Number
order deny, allow deny from ALL allow from 192.168.123
order deny, allow deny from ALL allow from .networkdomain.com
</Files> </pre> Where 192.168.123 is your internal network IP and .networkdomain.com is your Hostname/Domain. You can also switch it to allow from ALL and deny from a list of IPs or Hostnames.Here is a pratical example for advance users: <pre> <Files [/path/filename]>
[Attributes to apply to file...]
Limiting Access by User