nginx重写规则http://example.org/img?src=a至A



我的URL格式: http://example.org/img?src=http://a.com/logo.png

我希望nginx将此请求重写为http://example.org/logo.png(不是RERL)

如何做?

src参数可作为$arg_src变量可用,但是,您需要使用if块来提取所需的零件。请参阅有关使用if的警告。

例如(您需要根据您的特定需求调整正则表达式):

location = /img {
    if ($arg_src ~ w(?<src>/w.*)$) {
        rewrite ^ $src last;
    }
}

请参阅此处的nginx文档,此处的正则表达式有用。

相关内容

最新更新