Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change $request_uri in nginx?

We get information from $_SERVER['REQUEST_URI'] not from $_GET or $_POST.

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;  
}
like image 851
Murat SAÇ Avatar asked Sep 18 '13 10:09

Murat SAÇ


People also ask

What is request URI in nginx?

According to NGINX documentation, $request_uri is the original request (for example, /foo/bar. php? arg=baz includes arguments and can't be modified) but $uri refers to the altered URI.


1 Answers

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;
}
like image 157
srain Avatar answered Sep 22 '22 10:09

srain