简体   繁体   中英

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

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';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM