Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rule based on HTTP HOST, is it possible?

         

klauslovgreen

10:46 am on Nov 28, 2006 (gmt 0)

10+ Year Member



i have two domains pointing to the same directory.
like

example1.com, example2.com

Now if somebody tries to access from example1.com, it should ask for HTTP Authentication.

I have googled every possible keyword without success.

Is it possible?

Thanks

phranque

2:30 pm on Nov 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i don't know if this "breaks it" for you but you could have example1.com go to /subdirectory/ which could have your .htaccess and then your preferred redirect to the root directory.

jdMorgan

2:50 pm on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We can reverse the logic, and using a combination of mod_setenvif, Apache core, mod_auth, and mod_access, we can cause Apache to NOT require authentication/authorization for example2.com or www.example2.com:

SetEnvIf Host ^(www\.)?example2\.com nologin
Require valid-user
Satisfy any
Allow from nologin

I have omitted all but the salient directives above -- Your authentication configuration will need to define the password, user, and group files as usual.

Ref: Authentication, Authorization, and Access Control [httpd.apache.org] and the documentation for the individual modules noted above.

Jim