英文:
Can ngnix server check for multiple params in the url making them serve same file?
问题
由于下面的两个“if语句”检查URL中不同的参数,例如第一个检查“flag1”,第二个检查“flag2”,但都服务于相同类型的文件,我想将这两个检查合并到一个“if语句”中:
location /app/ {
location ~ "^(.)/([^/]+)_flag.(.)$" {
try_files $uri $1/$2.$3 =404;
}
if ( $args ~ "^.*flag1.*$" || $args ~ "^.*flag2.*$" ) {
rewrite "^(.*)/([^/]+(?<!_flag))\.(.*)$" "$1/$2_flag.$3" last;
}
}
英文:
Since both of the below 'if statements' serve the same type of file but check for different parameters in the URL, like the first one checks for 'flag1' and the second one checks for 'flag2', I want to merge both of these checks into just one 'if statement' serving that file:
location /app/ {
location ~ "^(.*)/([^/]+)_flag\.(.*)$" {
try_files $uri $1/$2.$3 =404;
}
if ( $args ~ "^.*flag1.*$" ) {
rewrite ^(.*)/([^/]+(?<!_flag))\.(.*)$ $1/$2_flag.$3 last;
}
if ( $args ~ "^.*flag2.*$" ) {
rewrite ^(.*)/([^/]+(?<!_flag))\.(.*)$ $1/$2_flag.$3 last;
}
}
Can this be possible?
答案1
得分: 1
是的,这是可能的。你应该使用or
条件:
if ( $args ~ "(^.*flag1.*$)|(^.*flag2.*$)" )
英文:
Yes it's possible. You should use or
condition:
if ( $args ~ "(^.*flag1.*$)|(^.*flag2.*$)" )
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论