Apache Authentication – Apache .htaccess Trick to Authenticate Only Once for All Subdomains

.htaccessapache-2.2authenticationsubdomain

I'm using something like this in .htaccess file to restrict access to the website:

AuthUserFile /some/directory/.passwd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require valid-user

This works fine but the user is asked to authenticate each time a subdomain is changed, like user1.mywebsite.com, user2.mywebsite.com or just mywebsite.com

Is there a way to tell Apache2 that when a user is authenticated against one subdomain, it should grant him access to all others as well?

Best Answer

Not possible; you can use a single .htaccess file to grant access to anything in your directory tree with the same credentials, but authentication is required for each unique subdomain.

As Benny points out, you'll need session-based authentication in some form to accomplish this.