I am trying to migrate a php-website running the symfony framework to nginx and php over fastcgi.
It all works well usining the Symfony howto from http://wiki.nginx.org/ but I run into trouble with a custom rewrite rule.
My goal is to rewrite urls of of the form /aaaa to /view/shorthand/aaaa. The request should then be handeled by php and symfony.
Old apache rewrite rule:
RewriteRule ^([0-9a-f]+)$ index.php/view/shorthand/$1 [L]
Nginx rules i have tried:
rewrite ^/([0-9a-f]+)$ /view/shorthand/$1 break;
rewrite ^/([0-9a-f]+)$ /index.php/view/shorthand/$1 break;
They all get sent to fastcgi but the request_uri still seems to be /aaaa since I get this error:
FastCGI sent in stderr: "Action "aaaa/index" does not exist" while reading response header from upstream
I have also tried using try_files without any luck. Please advice.
The problem is in default FastCGI variables set (fastcgi_params
config file), where REQUEST_URI
is equal to nginx's $request_uri
. But if you carefully read Nginx documentation, you will notice the difference between $request_uri
and $uri
variables.
$request_uri
= full original request URI (with arguments) $uri
= current URI in request, normalized The value of $uri
may change during request processing, e.g. when doing internal redirects, or when using index files. So, if you want to fix REQUEST_URI
value before it passed to PHP, just change $request_uri
to $uri?$args
in fastcgi_params
.
It's the way Nginx lead developer Igor Sysoev recommends in the official mailing list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With