views:

32

answers:

2

Say I have a htaccess file shared by "dev.server" and "server.site.com".

The first domain should allow all users to access it unchallenged (it only exists on my local development server).

The second domain I want to authenticate users with Apache (NOT by database).

The code to authenticate users is:

AuthType Basic
AuthName "Server Admin"
AuthUserFile "/path/to/passwd"
require valid-user

What I can't do is make those 4 lines only matter if the domain is "server.site.com". How can I do this?

I searched for something like <IfEnv HTTP_HOST "site.server.com"> but had no luck.

A: 

As far as I know, this can't be done in a .htaccess file. You'd have to put this into a Directory or VirtualHost section, both of which can't be used in a .htaccess file.

You would have to define it in two separate files, or directly in the server's configuration in the VirtualHost section.

Pekka
+1  A: 

This appears to work, still need to do some testing on it though.

Order Deny,Allow
Deny from all

SetEnvIf Host domain.for.no.auth dev
Allow from env=dev

AuthUserFile .pwd
AuthType Basic
AuthName MySite
Require valid-user
Satisfy Any
Tim Green
Nice! Will upvote tomorrow (out of votes)
Pekka
This works perfectly. Thank you!
Coronatus