Difference between revisions of "Htaccess"

From mi-linux
Jump to navigationJump to search
 
Line 6: Line 6:
  
 
1. '''Open a terminal''' (command line) window
 
1. '''Open a terminal''' (command line) window
 +
 +
1 and a half. Type '''ssh [username]@mi-linux.wlv.ac.uk''' (i.e. ssh 0612345@mi-linux.wlv.ac.uk) and enter your password
  
 
2. "cd" to the folder you want to protect - for example "'''cd public_html'''"
 
2. "cd" to the folder you want to protect - for example "'''cd public_html'''"

Revision as of 12:09, 21 March 2007

How to protect your site with .htaccess files

Follow this step-by-step guide to prompt a web user to enter an account and password to enter your site.

In your public_html folder (or any subfolder you want to protect)...

1. Open a terminal (command line) window

1 and a half. Type ssh [username]@mi-linux.wlv.ac.uk (i.e. ssh 0612345@mi-linux.wlv.ac.uk) and enter your password

2. "cd" to the folder you want to protect - for example "cd public_html"

3. Enter the following command - "pwd" - it will print out the full path of your current location - something like "home/stud/0/9480432/public_html"

4. Select the full path with the mouse, and right click, and select "copy" from the menu

5. Enter the following command "htpasswd -c .htpasswd username" - you can replace "username" with anything you like - this will be the username that a user of your site has to enter

6. You will be prompted to enter a password - enter any password here - you are advised AGAINST using your university account password

7. You will be prompted to enter the password again.

8. This creates a file called ".htpasswd" in your current folder.

9. Finally create a file in a text editor (Kate, Gedit, etc) with the following content

 AuthName "Hello"
 AuthUserFile [paste your full path here]/.htpasswd
 AuthType Basic
 require valid-user

10. Save the file as ".htaccess" - it is important that the filename starts with a fullstop and is case-sensitive

11. Enter the command "chmod 666 .ht*" in the terminal

Try it out - try and access your site - you should be prompted to enter your username and password you created.

If you get an "internal server error" you have made an error in your .htaccess file, or didn't run the chmod command