symfony: Infinite Redirect Loop with schemes routing setting

I have the following controller with routing annotation:

/**
 * @Route("/checkout/", name="checkout", schemes = "https")
 */
public function indexAction(Request $request)
{
    //...do stuff
}

This works fine on my development server, however, on my production server, I get an infinite redirect route. I looked through the logs and it is caused by Symfony, not Apache. It does this over and over until my browser stops:

[2014-10-28 17:32:28] request.INFO: Matched route "checkout" (parameters: "_controller": "Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction", "path": "/checkout/", "permanent": "true", "scheme": "https", "httpPort": "80", "httpsPort": "443", "_route": "checkout") [] []

It doesn’t make sense because the page requested IS via HTTPS:

https://example.com/checkout/

I have no access_control settings in security.yml that cover this. The weird thing is that all the other controllers that don’t use the "schemes = “https” work.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Are you running nginx+php-fpm?

You need to specify an environment variable in the https vhost.

        fastcgi_param HTTPS on;

Turns out by having my SSL configuration set at the server level instead of at the VirtualHost level that Apache was not setting the PHP Server variable “HTTPS”, even though HTTPS was being used. By adding the various SSL directives directly into my VirtualHost entry, the problem is solved. Thank you so much for your help. I LOVE SYMFONY.

@merk Indeed _SERVER["HTTPS"] is “on” on my dev server but non-existent on my production server. Not really sure why, but obviously not a symfony problem.

@merk is totally right.

If his suggestion doesn’t help, I would go into the Request::isSecure method and put some temporary debug code. But basically, it’s pretty simple - unless you’re behind a proxy, load balancer, HTTP cache - basically any server that’s between you and your users (or have Apache poorly configured). If you are (which is the most likely issue), then you’ll need to add the IP address (or range) of your reverse proxy to the trusted_proxies configuration: https://github.com/symfony/symfony-docs/blob/master/cookbook/request/load_balancer_reverse_proxy.rst

Cheers!