问题
In the httpd.conf I would like to allow a main path but disallow a particular subfolder.
Any url with this pattern must be accepted:
/app-1.0/public
/app-1.0/images
/app-1.0/
but this one must be ignored / not allowed.
/app-1.0/private
I want to use this configuration on an apache version 2.2.3. I have read that that version does not support negatives regex, but I am not sure.
Many thanks in advance.
回答1:
If you want to disallow any paths that start with /app-1.0/
and then have private
, you can use
^/app-1\.0/(?!private).*
See the regex demo
Pattern explanation:
^
-start of string (remove if the text is not at the start)/app-1\.0/
- a literal/app-1.0/
text (the dot must be escaped to be treated as a literal dot)(?!private)
- a negative lookahead that fails the match (=disallows) if there is aprivate
text right after the current position.*
- any 0+ characters other than a newline
NOTE: In my original comment, I suggested /app-1\.0/(?!private$).*
pattern with a $
after private
. That pattern disallows (=does not match) a string that contains /app-1.0/private
at the end ($
is the end-of-string anchor).
来源:https://stackoverflow.com/questions/38250682/locationmatch-to-allow-a-main-url-excluding-specific-sub-folder