Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ . ]
 
[ Web Magic ]

Protecting Documents & Directories
.htaccess / .htpassword

[ line ]

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

[ line ]

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 ]

[ Back to Top | Home ]

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ Creative Computing ]

[ Recommend Our Site ]     [ Creative Computing ]     [ HTML 3.2 Validated ]

Copy & Copyright (c) 1998 - 2006   Creative Computing

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Please Click To Visit Our Friends At:
Home

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

HTML Tips
HTML Validation
CGI Tips
Web Security
Search Engines
Spam Mail

Online Services
META Tag
    Generator

Web Whois

Site Resources
Site Links
Earn Cash

DBMan FAQ

Creative Computing

Contact
Guest Book

[ Recommend ]

[ Site Map ]

    [ Cross ]

[ Creative's Health News ]

[.]