首页 > 解决方案 > 如何通过参数在nginx配置文件中实现if else条件

问题描述

我的网址是https://www.example.com/article_slug?amp=1(对于 amp 页面),网站网址是https://www.example.com/article_slug

我如何通过 URL 根据“?amp=1”在服务器配置文件中实现 if else 条件。

请帮我

标签: nginx

解决方案


AFAIK最好使用map 模块而不是ifnginx 配置中的语句。例如:

map $arg_amp $x {
    1        foo;
    2        bar;
    default  baz;
}

...

location / {
    add_header X-Foo $x;
    return 204;
}

推荐阅读