Thomas Bennett
Thomas Bennett

Reputation: 647

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

I'm not sure if Sonata has something to do with this or if its related to PHP-FPM, but on production, when following app.php, internal redirects are not followed. If I visit /profile and the link is /profile/, I am taken to the page that asks me to click on /profile/. After a lot of Googling and reading the Book, I'm not sure where to turn.

Here is my VirtualHost:

<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>

Inside web directory I have an .htaccess

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

I've hit the website at mysite.com/profile and mysite.com/app.php/profile and still get the same issue.

Thanks!

Upvotes: 0

Views: 239

Answers (1)

Alex Zheka
Alex Zheka

Reputation: 586

We checked with Eugene and here is 2 possible solutions

So first let's check why it happens

It happens coz in sonata bundle we have event listener for redirect like that

 // 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;
    }

and as you can get from this we can do one of two possible solutions

  1. add get param _sonata_page_skip=true
  2. overwrite in our bundle template for redirect and make response|raw

Upvotes: 1

Related Questions