password

Protect website with password

You may want to restrict the development site from search engine or from direct access. One of the popular way of doing so is to use Apache2 Basic Authentication.
Here we will be discussing on how to password protect your development site using Apache2 Basic Authentication which makes a use of .htaccess & .htpasswd files.

Steps:

1. Create & upload .htaccess file to the root of your dev site with the following content:

AuthName "Authorisation Required"
AuthUserFile "/path/to/.htpasswd"
AuthType Basic
require valid-user
ErrorDocument 401 "Authorisation Required"

Notes: If .htaccess file already exists then you can add the above code on the top.
Also note that omitting ‘ErrorDocument 401 “Authorisation Required”‘ line can lead to 404 error.
2. Create & upload the .htpasswd file to ‘AuthUserFile’ path with the following content:

foo:$apr1$yB1.9vIT$IVVBmq5vMauwsNR8CZdHQ.

Notes: Where ‘foo’ is the username and ‘$apr1$yB1.9vIT$IVVBmq5vMauwsNR8CZdHQ.’ is the MD5 encrypted password of ‘bar’.
That was just an example, in fact you can use any username/password combination.
In order to create encrypted password you can use some free online tool like:
http://www.htaccesstools.com/htpasswd-generator/

3. Now try to visit the dev site, you will get the screen similar as:

apache2-basic-authentication

And you will only be able to browse the dev site once the correct username/password are entered.

Hope this helps you in password protecting your site.

via: MagePsycho

Panagiotis

Written By

Panagiotis (pronounced Panayotis) is a passionate G(r)eek with experience in digital analytics projects and website implementation. Fan of clear and effective processes, automation of tasks and problem-solving technical hacks. Hands-on experience with projects ranging from small to enterprise-level companies, starting from the communication with the customers and ending with the transformation of business requirements to the final deliverable.