NGiNX Dynamic Rewrites from Query Parameters
JS
S
JavaScriptSimple rewrite script based on query string parameters. coderecipes.org/pathA/pathB/script.pl?paraA=10¶B=20 will be rewritten to : coderecipes.org/pathA/pathB/script.pl.1020 curl "coderecipes/pathA/pathB/script.pl?paraA=10¶B=20" Rewrite rules change part or all of the URL in a client request. References: https://www.nginx.com/blog/creating-nginx-rewrite-rules/
1location /pathA/pathB/script.pl {
2 set $need_redirect "";
3 if ($arg_paraA) {
4 set $need_redirect "A";
5 }
6
7 if ($arg_paraB) {
8 set $need_redirect "B$need_redirect";
9 }
10
11 if ($need_redirect = "BA") {
12 rewrite ^(.*)$ $1.$arg_paraA$arg_paraB;
13 }
14}Created on 9/2/2018