.htaccess allows a specific IP or username/pass

This example shows that .htaccess file allows a specific IP else username/pass.
Step one: allows specific IP add these lines to .htaccess file

Order Deny,Allow
Deny from all
allow from 123.456.78.90

Step two: create username/password and use them
First of all, you should create username/password file using htpasswd. Type in terminal: “htpasswd -c filename username” press enter and you should input your password (twice). After that you have a .htpasswd file. The file consists of like below line

sirin:$apr1$vp3kZPGK$HdkGNW2KmYO8GJnTe6oRl1

So, you can add these lines to .htaccess file

AuthType Basic
AuthName “Restricted”
AuthUserFile /Users/sirin/foo/bar/.htpasswd
Require valid-user

Step three: combine them
Finally, you combine them below: also adding “satisfy any” selector keyword

AuthType Basic
AuthName “Restricted”
AuthUserFile /Users/sirin/foo/bar/.htpasswd
Require valid-user
Order Deny,Allow
Deny from all
allow from 123.456.78.90
satisfy any

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s