如何在 nginx 中更改 $request_uri? [英] How to change $request_uri in nginx?
本文介绍了如何在 nginx 中更改 $request_uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们从 $_SERVER['REQUEST_URI']
获取信息,而不是从 $_GET
或 $_POST
.
We get information from $_SERVER['REQUEST_URI']
not from $_GET
or $_POST
.
我想定义 $request_uri
以将 /example
更改为 /module/controller/action
.请注意,我不想触发重定向.
I want to define $request_uri
to change /example
to /module/controller/action
. Please note that I do not want to trigger a redirect.
我尝试了下面的代码来做到这一点,但它不起作用.
I tried the code below to do this, but it doesn't work.
location /example {
rewrite /module/controller/action;
}
推荐答案
set $request_url $request_uri;
if ($request_uri ~ ^/example(.*)$ ) {
set $request_url /module/controller/action;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9090;
#include fastcgi.conf;
fastcgi_param REQUEST_URI $request_url;
#fastcgi_param REQUEST_URI $request_uri;
}
这篇关于如何在 nginx 中更改 $request_uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文