I'm stuck on what seems to be a trivial problem when generating a rewrite url using a map.
I've tried multiple regex, but can't get the map to match for both conditions.
$some_var is a variable that may or may not be passed from an upstream server and I want to rewrite a location, if it's present or not.
This is what I've got, but it's not working. Any help greatly appreciated!
map $some_var $rewrite_url {
# if $some_var has any value I want to match this (this never matches)
~(.*) /path/to/thing2.js;
# if $some_var is not present I want to match this (this always matches)
default /path/to/thing.js;
}
# elsewhere in server config
location /getThing.js {
rewrite ^ $rewrite_url;
}
I've tried multiple regex, but can't get the map to match for both conditions.
$some_var is a variable that may or may not be passed from an upstream server and I want to rewrite a location, if it's present or not.
This is what I've got, but it's not working. Any help greatly appreciated!
map $some_var $rewrite_url {
# if $some_var has any value I want to match this (this never matches)
~(.*) /path/to/thing2.js;
# if $some_var is not present I want to match this (this always matches)
default /path/to/thing.js;
}
# elsewhere in server config
location /getThing.js {
rewrite ^ $rewrite_url;
}