| |
Protecting Documents & Directories .htaccess / .htpassword
![[ line ]](img/line.gif)
Several functions can be performed using an .htaccess file. This file provides a means of providing password protection for both files and directories, custom error pages, and more. Remember to load your .htaccess and .htpassword files in ASCII mode!
- Creating Custom Error Pages
- Simply create a file called .htaccess
- Use the htaccess call: ErrorDocument then a space, then the 3 digit error code, another space, then the URL to the document you want to show as your error page. Sample:
- ErrorDocument 404 /404error.html
- How to Password Protect your Directories
- Create a file called ".htaccess" containing these lines:
AuthName members <-- change "members" to reflect what you are restricting
AuthType Basic
AuthUserFile /path/user/protected_dir/.htpasswd <-- change path, user, & directory
require valid-user
- Save the file above into the directory you are protecting.
- Next you need to create encrypted passwords for each user you are allowing in you protected directory.
- Create a file called ".htpasswd" Each user should be one a separate line.
username1:password1
username2:password2
- Save this file in your protected directory.
Users will now be required to login to access this protected directory.
- Prevent people from viewing directory contents
- In a .htaccess file in your root directory, place the line:
- Options -Indexes
- Use a different file as the index file
- In a .htaccess file in your root directory, place the line:
- DirectoryIndex index.html index.htm index.cgi /error.html
- The above code will look for index.html in the directory being accessed. If it is not found, it will look for index.htm. If that is not found, it will look for index.cgi.
- In order to make a specific page your main page, put this line in your .htaccess file:
- DirectoryIndex <filename>.html
- Redirect command
Note that you do not have the server info (http://) for the old location, but it is necessary for the new location. You can then redirect to locations outside of your site.
- Redirect any of the files in the /old_dir directory of your account to a corresponding new address. All files within the directory will be redirected.
- Redirect /old_dir http://www.new.com/new_dir
- Only redirect a specified file:
- Redirect /old_dir/anyfile.htm http://www.new.com/new_dir/anyfile.htm
- Block IP addresses
IP blocking does not prevent Perl scripts or FTP from accessing a directory. You may block IP addresses from a directory by using the following command in a .htaccess file inside the directory:
- deny from 000.000.000.000
- Place each command on it's own line.
- You may also specify only the first 2 or 3 number groups if you want to block groups of addresses.
- To block everyone from a directory (useful if you have a data directory that contains sensitive information) by using:
- deny from all
![[ line ]](img/line.gif)
[ Back to Top | Home ]
Copy & Copyright (c) 1998 - 2006 Creative Computing
Please Click To Visit Our Friends At:
|