在Nginx,PHP中删除参数

时间:2012-05-21 16:27:18

标签: php apache symfony nginx

我在安装Symfony2之后尝试访问此URL:

http://test/symfony/web/app_dev.php/

但它不起作用,因为尾随斜线,我得到404。

这些工作正常:

http://test/symfony/web/app_dev.php
http://test/symfony/web/app_dev.php?/

在Apache中,/ app_dev.php / something和/app_dev.php?/something是相同的。关于如何在Nginx中使用它的任何想法?

我尝试添加重写,没有运气:

    location / {
            try_files $uri $uri/ @rewrite index.html;
    }

    location @rewrite {
            rewrite ^/(.*\.php)/(.*)$ $1?/$2;
    }

2 个答案:

答案 0 :(得分:1)

这就是我所拥有的,它运作良好:

    location / {
            # Remove app.php from url, if somebody added it (doesn't remove if asked for /app.php on the root)
            rewrite ^/app\.php/(.*) /$1 permanent;

            try_files $uri $uri/ /app.php?$query_string;
    }

    location ~ \.php$ {
            try_files $uri = 404;
            # Below is for fastcgi:
            # fastcgi_pass    127.0.0.1:9000;
            # fastcgi_index   app.php;
            # include         /etc/nginx/fastcgi_params;
            # fastcgi_param   SCRIPT_FILENAME /mnt/www/live/current/web$fastcgi_script_name;
            # fastcgi_param   SERVER_PORT 80;
            # fastcgi_param   HTTPS off;
    }

答案 1 :(得分:0)

我终于偶然发现了一个对我有用的答案:

    location ~ /directory/(.*\.php)(/.*)$ {
            set $script_filename $1;
            set $path_info $2;
            fastcgi_param  PATH_INFO        $2;
            alias /place/directory/$1;
            include fastcgi_params;

https://github.com/plack/Plack/issues/281

以下是文档中的相关代码段:请注意,它们都没有为script_name或path_info使用nginx提供的FCGI参数,因为它已知是不正确的。

location / {
 set $script "";
 set $path_info $uri;
 fastcgi_pass unix:/tmp/fastcgi.sock;
 fastcgi_param  SCRIPT_NAME      $script;
 fastcgi_param  PATH_INFO        $path_info;