我的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文档,此处的正则表达式有用。