I'm currently have several websites with different subdomains. They have a common .htaccess file.
Example:
- sub1.domainname.com
- sub2.domainname.com
- sub3.domainname.com
- exclude.domainname.com
- sub4.domainname.com
- ...
And I would like to restrict access to one of them, lets say to exclude.domainname.com
.
The problem is that I also want to allow access to different static files that may be served from /files
folder (ex: exclude.domainname.com/files/images/image.png
).
I've fininshed with this one solution, but now, when I'm trying to access exclude.domainname.com
and after entering username and password I'm getting a Server Error message, however static files can be accessed easily without any restrictions.
I will be really appreciate for any help. Perhaps the probelm with SetEnvIf or with general logic.
Thank you in advance.
## Password Protection & Authentification ##
AuthType Basic
AuthName "Access Protection"
AuthUserFile "/path/to/the/.htpasswd"
require valid-user
# Exclude Environments
# Set env to deny access
SetEnvIf Host ^exclude\.domainname\.com$ deny_access
# Remove env to deny access
SetEnvIf Request_URI "files/*" !deny_access
Order allow,deny
Allow from all
Deny from env=deny_access
Satisfy any
## END Password Protection & Authentification ##
PS:
I also tried to set different Environments like allow and deny.
Even try to deny all, then set allow to all hosts except exclude.domainname.com
like this:
SetEnvIf Host ^(?!exclude)\w+\.domainname\.com$ allow_access
But without Success.