Q:

nginx location regex rule not working

We are trying to create a location rule on nginx side, but its not working as expected.  Below is the location rule 
 location ~* ".*\.legalcontent\.html\?path=\/legal\/.*" {
     return 200 'regex rule'; //Using this temporarily to confirm if rule is triggering
 }

Incoming URL is below, want to capture (.legalcontent.html?path=/legal/)
https://www.mycompany.com/myapp/myproduct/mysubpage.legalcontent.html?path=/legal/somepage
Tested regex separately on regex tool, seems to be good

But its not working, tried simple context roots to check if everything else is good. 
# Following simple rules works fine, but we want location to kick-in 
# only for specific condition
location /myapp {
    return 200 'myapp rule';
}

location /myapp/myproduct {
    return 200 'myapp myproduct rule';
}

Is there a way to handle location rule for this kind of input URL

A:

The location will only check the path of the request.  To check the arguments you must create a conditional with the $args variable. 
location ~* ".*\.legalcontent\.html$" {
    if ($args ~* "^path=\/legal\/.*") {
        return 200 'regex rule';
    }
}

