Htaccess: Difference between revisions

From Redbrick Wiki
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
Line 1: Line 1:
.htaccess
'''.htaccess'''


[ Author : Declan McMullen (skyhawk) : 2003] [ Updated : John Doyle (art_wolf) : June 2004 ]
Redbrick's Webserver, apache, allows users to password protected certain sections of their websites via a method known as "htaccess".


RedBricks WebServer (apache) allows user to password protected certain section of their website via a method known as htaccess.
This is done by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect.


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


The password file comes first
The password file comes first. To create a htaccess password file and assign an authorized user to it type:


To create a htaccess password file and assign an authorized user to it type:
htpasswd -c ~/passwd username


htpasswd -c ~/passwd username
You can give the password file any name you like, just substitute the name you choose for passwd above. In this tutorial, references to passwd mean your password file. The value of username is the name of the user that you wish to grant access to. After running this command, you will be prompted to enter a password. This is the password that will be used by that user to gain access.


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
To allow the server access to query this file you will need to change its file permissions. Type the following into your terminal:


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
chmod 755 ~/passwd


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


Type the following into your terminal:
== Directory Creation ==


chmod 755 ~/passwd
Next, you create a directory that will be protected by the password file you just made. For the tutorial, we will call this directory "secret", but you can call it whatever you want.


That completes the configuring of the password file
Type the following into your terminal:
Directory Creation


Next you have to create a directory that will be protected by the password file
mkdir ~/public_html/secret


We will call this directory secret but you can call it whatever you wish
Once again the correct permission must be set. Simply type the following into your terminal:


Type the following into your terminal:
chmod 711 ~/public_html/secret


mkdir ~/public_html/secret
Now you're almost done.


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


chmod 711 ~/public_html/secret
With the password file and protected directory in place all that remains is the .htaccess file to tie it all together. The .htaccess file is what will tell the Webserver that the directory is password protected and requires authorisation.


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
Click [http://www.redbrick.dcu.ie/help/tutorials/htaccess/htaccess.txt here] for a sample .htaccess file
.htaccess file


The .htaccess file is what will tell the WebServer that the directory is password protected and requires authorization
Change to your protected directory by typing:


Click here for a sample .htaccess file
cd ~/public_html/secret


Change into your protected directory by typing:
Now type nano .htaccess to open the file in a text editor


cd ~/public_html/secret
Copy and paste the contents of the sample htaccess file into the editor, making the necessary modification to the AuthUserFile line, and save.


Now type nano .htaccess to open a text editor
'''Note:''' keep the name of the file .htaccess - this is an actual file extension recognised by Apache and it must be used.


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:


Lastly we need to set the permission on the file by typing:
chmod 755 .htaccess


chmod 755 .htaccess
== Testing ==
Testing


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


redbrick.dcu.ie/~username/secret
www.redbrick.dcu.ie/~username/secret


If all works correctly you should now be prompted for a username and password to gain access
If all works correctly you should now be prompted for a username and password to gain access. If you'd like to give access to another user, this is easily done using a similar command syntax to before:


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


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.


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
As always, you can contact [[Helpdesk]] if you have any problems.

Revision as of 06:08, 10 February 2007

.htaccess

Redbrick's Webserver, apache, allows users to password protected certain sections of their websites via a method known as "htaccess".

This is done by creating a password file for authorized users and a .htaccess file in the directory which you would like to protect.

Setting a password

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 this tutorial, references to passwd mean your password file. The value of username is the name of the user that you wish to grant access to. After running this command, you will be prompted to enter a password. This is the password that will be used by that user to gain access.

To allow the server access to query this file you will need to change its file permissions. Type the following into your terminal:

chmod 755 ~/passwd

Done!

Directory Creation

Next, you create a directory that will be protected by the password file you just made. For the tutorial, we will call this directory "secret", but you can call it whatever you want.

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 you're almost done.

.htaccess file

With the password file and protected directory in place all that remains is the .htaccess file to tie it all together. The .htaccess file is what will tell the Webserver that the directory is password protected and requires authorisation.

Click here for a sample .htaccess file

Change to your protected directory by typing:

cd ~/public_html/secret

Now type nano .htaccess to open the file in 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.

Note: 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:

www.redbrick.dcu.ie/~username/secret

If all works correctly you should now be prompted for a username and password to gain access. If you'd like to give access to another user, this is easily done using a similar 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.

As always, you can contact Helpdesk if you have any problems.