以“/start/”开头的正则表达式但不以“end1”结尾或“end2”
我试图制定一个正则表达式,与 httpd.conf 文件内 Apache Web 服务器配置的“Location”指令一起使用。
<Location ~ "/start/.*(?!end1|end2)$">
Order Deny,Allow
Deny from all
Allow from foo.com
</Location>
但是,我在 Apache 日志文件中收到以下错误:
Syntax error on line 1179 of c:/apache/apache/conf/httpd.conf:
Regex could not be compiled
我知道错误可能出现在“负向前瞻”部分:(?!end1|end2),但无法准确弄清楚。 谢谢
I was trying to formulate a regular expression to be used with "Location" directive of Apache web server configuration inside httpd.conf file.
<Location ~ "/start/.*(?!end1|end2)$">
Order Deny,Allow
Deny from all
Allow from foo.com
</Location>
However, I got the following error in Apache log file:
Syntax error on line 1179 of c:/apache/apache/conf/httpd.conf:
Regex could not be compiled
I know the error is probably in the "negative lookahead" section: (?!end1|end2), but could not figure out exactly.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache 1.x 使用 POSIX 扩展正则表达式,并且这些表达式
不支持 lookaround。
所以你的问题就在这里:
(?!end1|end2)
Apache 1.x uses POSIX Extended Regular Expressions and with these expressions
lookaround is not supported.
So your problem lies here :
(?!end1|end2)
正斜杠一般需要转义:
Forward slashes generally need to be escaped: