LocationMatch to allow a main url excluding specific sub folder

孤者浪人 提交于 2020-01-03 02:24:07

问题


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



来源:https://stackoverflow.com/questions/38250682/locationmatch-to-allow-a-main-url-excluding-specific-sub-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!