Nginx “pretty urls”

nginxPHP

So essentially I'm currently facing a problem with getting the following to work.

http://example.net/url.php/value1/value2/value3

I've tried various methods of try_files, but none of them seem to be working. The above is literally all I need to be able to do, but this is the error that I'm coming up with:

Here is a copy of my current config.

            server {
                listen          80;
                server_name     example;
                error_log       /var/log/nginx/error.log;

                index           index.php;
                root            /www/example.net;

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

                location ~* \.php$ {
                    include fastcgi_params;
                    fastcgi_pass 127.0.0.1:9000;
                }
            }

I've tried a lot of combinations I've read from various tutorials for the try_files in location / and none of them have worked in the way that I've wanted. I've either got a 404 (if index.php isn't included in the end, because it's not finding the file or a directory) or a 500 error.

2013/01/23 07:21:35 [error] 1411#0: *1 rewrite or internal redirection cycle while internally redirecting to "/testing_nginx.php/test", client: 75.182.96.115, server: subeta, request: "GET /testing_nginx.php/test HTTP/1.1", host: "166.78.101.192"

Best Answer

You can use Nginx URL Rewriting. By instance can add this to your nginx.conf.

location / {
  rewrite  ^/pay/(.*)/(.*)$     /pay.php?p=$1&s=$2?   last;
  rewrite  ^/register$          /register.php?        last;

  location ~ \.ph[pb]$ {
    #PHP FASTCGI SETTINGS
  }
}