Apache config for all Location except specific URI

2019-05-26 18:54发布

I need to apply some configuration for a Location Directive.

These configurations must be applied for all location, except some URIs (e.g. I don't wanna change configs for /products, so bellow configuration must be applied for all locations, except /products )

<Location />
 # desired configurations
</Location>

1条回答
Evening l夕情丶
2楼-- · 2019-05-26 19:21

This can be done in several ways:

1. Using regex

Use regex in Location Directive to match all URIs, except your pattern

e.g.:

<Location ~ "^((?!/product).)*$">
# desired configurations
</Location>

  1. Using < If> directive: e.g.:

use If inside your directory:

<If "%{Request_URI} =! '.*/product.*'">

or

<If "%{Request_URI} =! '^((?!/product).)*$'">

  1. By setting variables and using If and IfDefine

Set a variable at start of configurations, and then use directive

SetEnvIf Request_URI ".*/product.*" isProd=1
...
<IfDefine isProd>
...

or you can use expr in If directive for comparing strings and variables.


Useful link

查看更多
登录 后发表回答