How do I set a location
condition in Nginx that responds to anything that isn't equal to the listed locations?
I tried:
location !~/(dir1|file2\.php) {
rewrite ^/(.*) http://example.com/$1 permanent;
}
But it doesn't trigger the redirect. It simply handles the requested URI using the rules in the rest of the server configuration.
i was looking for the same. and found this solution.
Use negative regex assertion:
Source Negated Regular Expressions in location
According to nginx documentation
So you could define something like
Suppose you have two locations say,
location1
andlocation2
, you can try following location block configuration to solve your problem.Also the problem you are facing could be because of the sequence of multiple location block in your configuration. Please check, In case any of the location block that comes before this, serves the request.