0

I got the following directories in my /var/www/htdocs:

test123/
test123/cache/
test456/
test456/cache/
test789/
test789/cache/
another_directory/cache/

I would like to achieve this:

  • access to / for everyone
  • access to /test123/test.htm + /test456/test.htm + /test789/test.htm for the ip-address 192.168.1.10
  • no access to all cache-directorys

So I got the following apache 2.4 configuration, but it is not working as expected, because I am still able to access the cache-directories test123/cache, test456/cache and test789/cache.

<VirtualHost *:80>
        DocumentRoot /var/www/htdocs

        <Directory "/var/www/htdocs">
                Options -Indexes +FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory  ~ "/var/www/htdocs/test(123|456|789)">
                Require ip 192.168.1.10
        </Directory>

        <Directory  "/var/www/htdocs/*/cache">
                Require all denied
        </Directory>
</VirtualHost>

What am I doing wrong? Thanks for your help! :)

0

Quotes from the documentation:

  • <Directory> [...] is processed in the order shortest directory component to longest. For example, <Directory "/var/web/dir"> will be processed before <Directory "/var/web/dir/subdir">.
  • If multiple <Directory> sections apply to the same directory they are processed in the configuration file order.

This makes your case a little difficult.

From the second statement I'd interpret that it should only be necessary to switch the order of the two <Directory> directives:

<Directory  "/var/www/htdocs/*/cache">
        Require all denied
</Directory>

<Directory  ~ "/var/www/htdocs/test(123|456|789)">
        Require ip 192.168.1.10
</Directory>

If the first matches, it gets denied. Otherwise the second directive should match.

The first statement, however states that the shortest directory is processed first. The shortest here would be the <Directory ~ "/var/www/htdocs/test(123|456|789)">. In that case the order doesn't matter and you will have to look for another solution.

I can't test it right now, so just try to switch the two statements.

  • Thanks for your reply! I was not aware of the shortest first, I think I missed that information in the documentation. I already tried to change the order in the configuration file and it did not help :( – Tobi As Aug 25 '17 at 13:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.