带有 PHP-FPM 的 Sonata Admin Symfony2 未遵循生产环境的内部重定向

Sonata Admin Symfony2 with PHP-FPM Not Following Internal Redirects on Production

我不确定 Sonata 是否与此有关,或者它是否与 PHP-FPM 相关,但在生产中,当跟随 app.php 时,不会遵循内部重定向。如果我访问 /profile 并且 link 是 /profile/,我将被带到要求我单击 /profile/ 的页面。经过大量谷歌搜索和阅读本书后,我不确定该去哪里。

这是我的虚拟主机:

<VirtualHost *:80>
  ServerName mysite.com
  ServerAlias www.mysite.com mysite.com
  DocumentRoot /var/www/mysite/web
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  <FilesMatch \.php$>
      SetHandler proxy:fcgi://127.0.0.1:9000
  </FilesMatch>

  <Directory /var/www/mysite/web>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Require all granted
  </Directory>

在 web 目录中我有一个 .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

我访问了 mysite.com/profile 和 mysite.com/app.php/profile 的网站,但仍然遇到同样的问题。

谢谢!

我们与 Eugene 进行了核实,这里有 2 种可能的解决方案

所以首先让我们检查一下为什么会这样

它发生在奏鸣曲包中,我们有这样的重定向事件监听器

 // display a validation page before redirecting, so the editor can edit the current page
    if ($page && $response->isRedirection() && $this->cmsSelector->isEditor() && !$request->get('_sonata_page_skip')) {
        $response = new Response($this->templating->render('SonataPageBundle:Page:redirect.html.twig', array(
            'response'   => $response,
            'page'       => $page,
        )));

        $response->setPrivate();

        $event->setResponse($response);

        return;
    }

正如您从中得到的那样,我们可以采用两种可能的解决方案之一

  1. 添加获取参数 _sonata_page_skip=true
  2. 在我们的包模板中覆盖重定向并使 response|raw