How to change $request_uri in nginx?

muratsac asked:

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

not redirect.

I tried code blow to do this but it doesn’t work.

location /example {
    rewrite /module/controller/action;  
}

My answer:


You don’t need rewrites for this, just try_files.

location / {
    try_files $uri $uri/ /index.php;
}

In this case, nginx will serve static files, and anything else will be passed to /index.php for handling.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.