in Web & Tech

Htaccess-Authentication based on Host name

Let’s say you have a multisite installation with several (sub)domains pointing to the same document root. Now, you want to protect private.domain.com with ht-authentication while www.domain.com stays publicly available.
Please welcome Apache’s setEnvIf as your friend:

AuthName "Private" 
AuthType Basic 
AuthUserFile /var/www/.htpasswd
require valid-user

SetEnvIf Host private.domain.com secure_content

Order Allow,Deny
Allow from all
Deny from env=secure_content

Satisfy Any

Source: http://stackoverflow.com/a/6953716/93261

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)