"Never memorize something you can look up", Albert Einstein

Apache htpasswd if not certain IP

This is a reoccuring problem I frequently come across when developing website’s:

You have one or more files that are accessible from the web but you only want them to be available when the user enters the right user/password combination.

No problem you say here with an htaccess/htpasswd protection this is solved.

Only when you want to have a cronjob script to access those same files you need to write authentication and store an user/pass combination in this script.

Well, I finally found a way to tell Apache to check for a certain IP (127.0.0.1) and allow that or force the user to authenticate with htpasswd.

How?

AuthUserFile /path/to/user.pass
AuthGroupFile /dev/null
AuthName "Private"
AuthType Basic
Satisfy Any


order deny,allow
deny from all
allow from 127.0.0.1
require valid-user

Give special attention to ‘Satisfy Any’ in the above code, this will configure Apache to allow access by IP or user/pass combination.

 


Only members are allowed to post a comment.

Comments

Geplaatst door WilliamFarthowe op 06-Dec-11 13:12

I’ve read your post and I’m interested on it. Thank you for sharing. When Essay Writing Help me with of some code and your blog post appears on it. thanks!