Nugorra
Nugorra

Reputation: 1

request only htaccess auth for one of many domains

I have a system where x domains could lead to the same folder on the server.
(content is shown by the Database for the given domain)

Now I want to develop a new page but I would need a htaccess auth only for this domain.

example1.com ok
example2.com auth
example3.com ok

Any idea?

Upvotes: 0

Views: 55

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You can use SetEnv directives to setup a "pass through" for the hosts that don't need HTTP authentication. The rest is the same as setting up HTTP Auth:

# Set the PROTECTED_HOST env var if the hostname is example2.com
SetEnvIfNoCase HOST example2.com PROTECTED_HOST

# basic HTTP Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic
Order Deny,Allow
Deny from all

# Use satisfy any for either ENV or required user
Satisfy any

Require valid-user
Allow from env=!PROTECTED_HOST

Upvotes: 3

Related Questions