I have a directory (path/to/directory/
) in which there is a .htacces blocking access using Require valid-user
to require an authentication.
Now my task is to allow access to a subdirectory(path/to/director/foobar
) and anything that might be in that subdirectory.
I do know how to grant access to a specific file by matching the request with the file path.
However, I do not know how the structure will look inside the directory.
I was wondering if it may be possible to check with a regular expression for the name of my directory?
so I considered
<RequireANY>
#Allow subdirectory
Require %{REQUEST_URI} ^(.*?(bfoobarb)[^$]*)$
#fallback
Require valid-user
</RequireANY>
The regex checks out in https://regex101.com/ to match any URI, with foobar
in it. Sadly the condition does not work like that. Did I miss something important as I am fairly unfamiliar with .htacces.? Thanks in advance
2
Answers
I found this solution to to exactly what I needed. I found it in an Installation Guide for Shopware 6
https://docs.shopware.com/de/shopware-6-de/erste-schritte/shopware-6-installieren
You may use this block with
<if>
expression:Negative lookahead regex pattern
^/path/to/directory/(?!foobar/)
will match/path/to/directory/*
except whenfoobar/
comes directly after it.