Htaccess

From Redbrick Wiki
Revision as of 05:54, 10 February 2007 by Undone (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

.htaccess

[ Author : Declan McMullen (skyhawk) : 2003] [ Updated : John Doyle (art_wolf) : June 2004 ]

RedBricks WebServer (apache) allows user to password protected certain section of their website via a method known as htaccess.

It is accomplished by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect. Password Setting

The password file comes first

To create a htaccess password file and assign an authorized user to it type:

htpasswd -c ~/passwd username

You can give the password file any name you like just substitute the name you choose for passwd above. In the tutorial references to passwd mean your password file

The value of username is the name of the user that you which to grant access to. You will be prompted to enter a password that will be used to grant access to that user. Follow the instructions and when completed that is your password file created

To allow the server access to query this file you need to change its file permissions.

Type the following into your terminal:

chmod 755 ~/passwd

That completes the configuring of the password file Directory Creation

Next you have to create a directory that will be protected by the password file

We will call this directory secret but you can call it whatever you wish

Type the following into your terminal:

mkdir ~/public_html/secret

Once again the correct permission must be set.Simply type the following into your terminal:

chmod 711 ~/public_html/secret

Now your almost done.With the password file and protected directory in place all the remains is the .htaccess file to tie it all together .htaccess file

The .htaccess file is what will tell the WebServer that the directory is password protected and requires authorization

Click here for a sample .htaccess file

Change into your protected directory by typing:

cd ~/public_html/secret

Now type nano .htaccess to open a text editor

Copy and paste the contents of the sample htaccess file into the editor, making the necessary modification to the AuthUserFile line , and save in the usual manner. Note do keep the name of the file .htaccess - this is an actual file extension recognised by Apache and it must be used.

Lastly we need to set the permission on the file by typing:

chmod 755 .htaccess Testing

To test if the directory is protected correctly type its url into a browser eg:

redbrick.dcu.ie/~username/secret

If all works correctly you should now be prompted for a username and password to gain access

If you wish to give another user access at any time this is easily done using a similiar command syntax to before

htpasswd ~/passwd username

You'll be prompted to enter the new password twice as you were before. Once entered the new user is active immediately and can gain access to the protected directory