.htaccess. deny root, allow specific subfolder. Possible?

前端 未结 4 2001
失恋的感觉
失恋的感觉 2020-12-14 08:51

How can I deny access to http://sub.mydomain.com/, but allow for (completely) http://sub.mydomain.com/test (or http://sub.mydomain.com/test/)

There is a magento back

4条回答
  •  生来不讨喜
    2020-12-14 09:22

    I know this is a very old thread, but I've been struceling with exactly this scenario for several days and finally got it to work, thus I thought I'd share my solution for further reference.

    As of Apache version 2.4 (I guess), it's possible to use directive and . This can be used to allow access to specific subfolders.

    My solution for .htaccess (inspired from this site: https://www.the-art-of-web.com/system/apache-authorization/):

    SetEnvIf REQUEST_URI "^/test/.*" PUBLICACCESS
    # Use for multiple subfolders:
    # SetEnvIf REQUEST_URI "^/(?:test|test2|test3|test4)/.*" PUBLICACCESS
    
        
            # Public access
            Require env PUBLICACCESS
            Require all granted
        
        
            # Require user and password
            AuthType Basic
            AuthName "Secured"
            AuthUserFile /var/www/example.com/.htpasswd
            Require valid-user
        
    
    

提交回复
热议问题