487
edits
m (Reverted edits by Upazixorys (Talk); changed back to last version by Olajideolaolorun) |
(Updated link) |
||
Line 1: | Line 1: | ||
This article will help you understand and | This article will help you understand some aspects and advantages of the .htaccess file you see when you run an Apache Web Server like ours. | ||
==What is a .htaccess file?== | ==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 | 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 the web server operates. When it is placed in a particular directory, the rules in it apply to that directory and all the subdirectories thereof. | ||
Here is a [http://www.javascriptkit.com/howto/htaccess.shtml good tutorial] | Here is a [http://www.javascriptkit.com/howto/htaccess.shtml good tutorial] on the use and configuration of the .htaccess file. | ||
==What is a .htpasswd file?== | ==What is a .htpasswd file?== | ||
Line 15: | Line 13: | ||
===Change the Default Directory Index File=== | ===Change the Default Directory Index File=== | ||
It can be used to | It can be used to change the default index file, which is normally index.html, index.ext... to anything else, like foo.ext or whatever name/extension you prefer. To do this, use: | ||
<pre>DirectoryIndex foo.ext home.html home.php foo.php</pre> | <pre>DirectoryIndex foo.ext home.html home.php foo.php</pre> | ||
===Customizing Error Handling/Error Pages=== | ===Customizing Error Handling/Error Pages=== | ||
If you have ever wondered how people | If you have ever wondered how people change their 404, 500... error pages to something like lost.ext, then you will like this code in your .htaccess file: | ||
<pre> | <pre> | ||
<nowiki> | <nowiki> | ||
Line 26: | Line 24: | ||
</nowiki> | </nowiki> | ||
</pre> | </pre> | ||
Where [Error Number] is replaced with the error number, and [Error Document] is replaced with the path | Where [Error Number] is replaced with the error number, and [Error Document] is replaced with the path to the error document, which can be internal or external, as in: | ||
<pre>http://www.anothersite.com/foo.ext or /foo.ext</pre> | <pre>http://www.anothersite.com/foo.ext or /foo.ext</pre> | ||
Line 74: | Line 72: | ||
===Limiting Access by User=== | ===Limiting Access by User=== | ||
This part lets you use a .htaccess/.htpasswd user login system | This part lets you use a .htaccess/.htpasswd user login system which uses cookies. It is only partly secure because the session does not expire until all open browsers are closed, so try not to use it on a site section that needs fool-proof security. Here is the code: | ||
<pre> | <pre> | ||
AuthType Basic | AuthType Basic | ||
Line 81: | Line 79: | ||
Require valid-user | Require valid-user | ||
</pre> | </pre> | ||
For this example you | For this example, you place a .htpasswd file in the path (/htpasswd/path/to/). In the .htpasswd file will be: <pre>[user]:[password]</pre> Normally you have to encrypt the password but if you are using [[The_Uniform_Server|The Uniform Server]], then you do not need to do that. You ca also use this example to protect another directory from just 1 .htaccess file: | ||
<pre> | <pre> | ||
<Directory /path/to/> | <Directory /path/to/> | ||
Line 90: | Line 88: | ||
</Directory> | </Directory> | ||
</pre> | </pre> | ||
If you | If you want to do this for just specific files, then use: | ||
<pre> | <pre> | ||
<Files /path/to/file.ext> | <Files /path/to/file.ext> | ||
Line 99: | Line 97: | ||
</Files> | </Files> | ||
</pre> | </pre> | ||
The ''Require'' statement is used to list valid users or groups of users | The ''Require'' statement is used to list valid users or groups of users. If you just want one .htpasswd file but want multiple protected areas, then you can use: | ||
<pre>Require user username1 username2 username3...</pre> | <pre>Require user username1 username2 username3...</pre> | ||
Or if you want to use it in groups then you can use: | Or if you want to use it in groups then you can use: | ||
Line 111: | Line 109: | ||
Groupname2: username1 username4 username5 .... | Groupname2: username1 username4 username5 .... | ||
</pre> | </pre> | ||
As you can see a username may be in as many | As you can see, a username may be in as many groups as you like while others may be in only one. | ||
[[Category: Troubleshooting ]] | [[Category: Troubleshooting ]] | ||
[[Category: Application]] | [[Category: Application]] | ||
[[Category: Development]] | [[Category: Development]] |