Nginx重写规则,所有.php文件/请求被index.php解析


Nginx Rewrite Rule for all .PHP files/requests to be parsed by index.php

是否有任何神奇的重写(就像它在Apache上一样)nginx能够重写url,如'/submit.php',以便能够从index.php处理它们?我们有很多404未发现错误,因为网站的结构和所有以前的url都像'/address .php', '/my_settings.php', '/profile.php' -->有超过50个这样的文件,这将是非常不专业和代码不明智的创建一个单独的。php文件为每个这些函数,而不是解析他们所有通过index.php和使用所需的类,就像我们做的其他重写。

你今天能不能找到一个解决方案/给我们一个建议?

我认为这是这里的一些信息,但我想要完全相反的结果:http://www.nullis.net/weblog/2011/05/nginx-rewrite-remove-file-extension/

此配置允许您使用放置在/var/www/example.org/htdocs/index.php

中的一个php脚本处理所有URL(文件系统中不存在的文件)
server {
    listen   80; ## listen for ipv4
    server_name  example.org www.example.org;
    root            /var/www/example.org/htdocs;
    access_log      /var/log/nginx/example.org.access.log;
    error_log       /var/log/nginx/example.org.error.log;
    location / {
            index  index.php index.html index.htm;
            try_files $uri $uri/ @php;
    }
    # enable running php files under php fastcgi
    location ~ '.php {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /var/www/example.org/htdocs$fastcgi_script_name;
            #fastcgi_param  QUERY_STRING $uri;
            include fastcgi_params1;
    }
    location @php {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/example.org/htdocs/index.php; # this script catches all non existing URLs
            fastcgi_param  QUERY_STRING $uri;
            include fastcgi_params1;
    }
}