Murat SAÇ
Murat SAÇ

Reputation: 396

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;  
}

Upvotes: 10

Views: 47550

Answers (1)

srain
srain

Reputation: 9082

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;
}

Upvotes: 20

Related Questions