LocationMatch允许主网址排除特定的子文件夹 [英] LocationMatch to allow a main url excluding specific sub folder

查看:162
本文介绍了LocationMatch允许主网址排除特定的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在httpd.conf中,我想允许使用主路径,但不允许使用特定的子文件夹.

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/public

/app-1.0/images

/app-1.0/images

/app-1.0/

但这必须被忽略/不允许.

but this one must be ignored / not allowed.

/app-1.0/private

/app-1.0/private

我想在2.2.3版的apache上使用此配置.我已经知道该版本不支持负数正则表达式,但是我不确定.

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.

非常感谢.

推荐答案

如果您要禁止以/app-1.0/开头并具有private的任何路径,则可以使用

If you want to disallow any paths that start with /app-1.0/ and then have private, you can use

^/app-1\.0/(?!private).*

请参见 regex演示

模式说明:

  • ^-字符串的开头(如果文本不在开头,则删除)
  • /app-1\.0/-文字/app-1.0/文本(点必须转义以视为文字点)
  • (?!private)-如果当前位置之后紧跟着是private文本,则负向超前行为将使匹配失败(=不允许)
  • .*-除换行符外的任何0+个字符
  • ^ -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

注意:在我最初的评论中,我建议在private之后加上$/app-1\.0/(?!private$).*模式.该模式不允许(=不匹配)结尾处包含/app-1.0/private的字符串($是字符串结尾锚点).

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

这篇关于LocationMatch允许主网址排除特定的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆