Gandi Wiki


Questions

Protecting your website by .htaccess

If you want to protect your website so that it can only be accessed by someone who has a username and password, you can do so by using .htaccess. The following is just an example of one way to do this.

Step 1: make a .htpasswd file

Start by opening up a plain text editor like notepad, and adding a line that contains your username and password, separated by a colon. The password will need to be encrypted in a special format that can be used for htaccess password protection. There are many online tools to help with this such as: http://www.tools.dynamicdrive.com/password/

The contents of your .htpasswd will look something like the following (this is an EXAMPLE, yours will have your own username and password):

ryan:oeteHNuwJnH7k

Then, save your file as .htpasswd and upload it (using ASCII and not BINARY) to your instance, directly in the virualhost diectory that has the name of your virtualhost (don't put it in the htdocs folder!)

Step 2: make a .htaccess file

Also in a plain text editor, add some content like the following:

AuthUserFile /srv/data/web/vhosts/yourvirtalhostname/.htpasswd
AuthName "Password Protected Area"
AuthType Basic

<limit GET POST>
require valid-user
</limit>

You can personalize the password prompt by changing what comes after AuthName.

You can then upload this file to the root of your virtualhost to protect the entire site.

Questions

RSS feed for questions matching this filter (Help)

Last modified: 04 Feb 2012 at 22:19 by Ryan A. (Gandi)