nginx配置重定向时如何带参数$args重定向
当使用nginx配置重定向时,可以通过使用rewrite指令和return指令来实现带参数的重定向。
使用rewrite指令时,可以在重定向时使用$args变量来获取原始请求中的参数。例如:
location /old-url {
rewrite ^/old-url/(.*)$ /new-url/$1?$args permanent;
}
上述配置会将/old-url重定向到/new-url,并保留原始请求中的所有参数。
另一种方法是使用return指令。在return指令中,可以使用$args变量来重定向时带上参数。例如:
location /old-url {
return 301 /new-url?$args;
}
上述配置会将/old-url重定向到/new-url,并保留原始请求中的所有参数。
无论是使用rewrite还是return指令,都可以使用$args变量来获取原始请求中的参数,并将其带到重定向的URL中。
原文地址: https://www.cveoy.top/t/topic/hN7h 著作权归作者所有。请勿转载和采集!