0

I'm currently have several websites with different subdomains. They have a common .htaccess file.

Example:

  1. sub1.domainname.com
  2. sub2.domainname.com
  3. sub3.domainname.com
  4. exclude.domainname.com
  5. sub4.domainname.com
  6. ...

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
solosik
  • 11
  • 2
  • Unfortunately not. My solution is almost working: it asks username & password for subdomain and allow access to static files, but it ends up with Server Error after entering username/password for subdomain. – solosik Nov 17 '16 at 13:50
  • Sorry this was the link to another answer... https://regex101.com/r/EQKCDv/2 – Nicolas Nov 17 '16 at 13:52
  • Sorry, but this is just the same regex as I tried too inside my PS section. I suppose that something wrong with **SetEnvIf** or with the logic in general – solosik Nov 17 '16 at 13:56

0 Answers0