1

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.

Alejandro
  • 134
  • 2
  • 5

1 Answers1

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 a private 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).

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • This doesn't seem to work within LocationMatch, as the path passed to the handler ends up including the regexp. Tested with ````. – Pietro Battiston Jul 22 '20 at 18:08
  • @PietroBattiston I do not know what your requirements are (your regex is different). If you want to match any string but the one containing `piwik`, use `` – Wiktor Stribiżew Jul 22 '20 at 18:22
  • the aim of my regex was to get everything but the ``/piwik`` path, but I now realize I have a more general problem, sorry - when I use ``LocationMatch`` with inside a ``SetHandler uwsgi-handler``, this ends up polluting the path that is passed to my uwsgi script, so that the regex itself appears the website's links. – Pietro Battiston Jul 22 '20 at 21:32