在重写url后,Symfony不会正确读取基本路径

时间:2017-12-28 22:59:19

标签: php symfony nginx

我使用此nginx配置重写了从/api/(.*)$/api/public/index.php/$1的所有网址:

location /api/ {
    try_files $uri @rewriteindex;
}
location @rewriteindex {
    rewrite ^/api/(.*)$ /api/public/index.php/$1 last;
}
location ~ ^/api/public/index\.php(/|$) {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
}

一切都按预期工作但当我导航到/api/something(正确映射到/api/public/index.php/something)时,symfony正在搜索/api/something/路由而不是something,从而触发了错误,因为路线不存在。

如何让symfony获取相对于/api/文件夹的路由?

0 个答案:

没有答案