MrR*_*ing 2 regex location config directive apache2
我需要为“位置指令”应用一些配置。
这些配置必须应用于所有位置,除了某些位置URIs(例如,我不想更改的配置/products,因此,波纹管配置必须应用于除/ products之外的所有位置)
<Location />
# desired configurations
</Location>
Run Code Online (Sandbox Code Playgroud)
这可以通过几种方式完成:
在位置指令中使用regex 匹配所有URI(模式除外)
例如:
<Location ~ "^((?!/product).)*$">
# desired configurations
</Location>
Run Code Online (Sandbox Code Playgroud)
在目录中使用If:
<If "%{Request_URI} =! '.*/product.*'">
Run Code Online (Sandbox Code Playgroud)
要么
<If "%{Request_URI} =! '^((?!/product).)*$'">
Run Code Online (Sandbox Code Playgroud)
在配置开始时设置一个变量,然后使用指令
SetEnvIf Request_URI ".*/product.*" isProd=1
...
<IfDefine isProd>
...
Run Code Online (Sandbox Code Playgroud)
或者您可以在If指令中使用expr来比较字符串和变量。