uri 映射 - '/index.php/dashboard'

uri 映射 - '/index.php/dashboard'

在 Apache 中,我可以通过类似的 uri 访问 php 脚本/index.php/dashboard,如何设置 nginx 以执行相同的操作?

我也可以/index使用 Apache 访问,它会自动映射到/index.php。在 nginx 中也可以这样做吗?

我认为像这样的事情是解决方案:

map $uri $myvalue {
    /index.php/(.*)    /index.php?$;
}

或者有没有不需重写的解决方案?

更新,当前配置:

server {
        listen   80;
        charset utf-8;
        root /www/public;
        index index.php index.html index.htm;
        access_log  /www/log/access.log;
        error_page 404 /www/public/http-404.php;
        server_name rasp;

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        location ~ /\.ht {
                deny all;
        }

        location / {
                autoindex on;
                try_files $uri $uri/ $uri.php /;
        }


        location /dev/ {
                auth_basic "dev";
                auth_basic_user_file /www/config/global.passwd;
                location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                }
        }

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

答案1

我不确定这是否存在任何安全问题,这是我在测试环境中使用的

if (!-e $request_filename)
{
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
}

location ~ \.php    {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /path/to/index.php;
        fastcgi_index index.php;
        fastcgi_param DOCUMENT_ROOT /path/to;
    }

相关内容