Pages

Wednesday, September 1, 2010

Password protection to website directory - .htaccess

A simple technique to protect the website folder from access is as given below.

Step 1:

Create a simple file with an extension .htaccess

Step 2:

Create a simple file with an extension .htpasswd

Step 3:

Copy the given below commands in the .htaccess file and save it.

AuthName "folder name"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user


- the folder name is the website folder you need to do password protect
- /full/path/to is the full path of the .htpasswd file

Step 4:

Give the username and password as like below in the .htpasswd file and save it.

username:password

- username is the normal user name that you can give for protection
- password is the encrypted form of your password that you can give for protection
(You can get the encrypted code from the KXS website )

Step 5:

Place the .htaccess file in the folder where you need to protect.

Step 6:

Place the .htpasswd wherever you want inside the ftp but you need to specify the full path of the file in the .htaccess file. The full path may vary based on the hosting provider. An easy way is there to find the full path. Download the following php file Path Info. Place the file where you want to know the full path. Access the php file from the server. It will give you the full path.

Thats it! Now if you try to access the files inside the folder, it will ask for the username and password and your work is done.

For more information, you can visit this, HtAccess Tutorial site