© copyright 01.Jan.2002 by Paul Bradley filed under Apache
The .htaccess file is plain ASCII text file which is used to configure the Apache web server at the directory level.
Nothing is more annoying to web users than the dreaded 404 file not found error message. Using the .htaccess file you can configure the server to display a web page of your choice when a 404 error is encountered.
For example, create a web page called custom404.html and upload it to your root directory. Then create a file called .htaccess using notepad and add the following line of code.
ErrorDocument 404 /custom404.html
Upload the .htaccess file to your root directory.
Using your Internet browser, try loading a file such as http://yourdomain/nosuchfile.html, this should cause a 404 file not found error, and the Apache web server will load your customised page.
If you need to set-up a members only section to your site, where people have to supply a valid username and password to login.
Assuming the directory you wish to protect is /members/ then add the following lines of code to the .htaccess file for the members directory.
AuthName "Members Only Section"
AuthType Basic
AuthUserFile /full/path/to/members/.htpasswd
<Limit GET>
require valid-user
</Limit>
ErrorDocument 401 /loginfailed.html
* Remember each directory can have its own .htaccess file.
The AuthUserFile line points to the full Unix path for the username and passwords file .htpasswd
The error document 401 command tells the web server which file to load when the user selects cancel on the password dialog, or enters the password incorrect three times.
The .htpasswd file is an ASCII text file containing a separate line for each username and password combination.
e.g.
member1:$1$member1$WMwlrep7TJdXaK3aDpIX90
member2:$1$member2$WMwlrep7TJdXaK3aDpIX90
About the Author
Paul Bradley is a VB.NET software developer living and working in Cumbria. He provides PHP & MySQL bespoke development services via his software development company, Carlisle Software Limited.
He has over 20 years programming experience.