How to force https for prod but http for dev environment?

后端 未结 4 1400
孤街浪徒
孤街浪徒 2021-02-02 11:13

I have a symfony2 application.

On the prod server I want all my routes to go via https, while in dev I want to be able to use http. How do I achieve that with symfony2 a

4条回答
  •  广开言路
    2021-02-02 11:31

    Change your app.php last lines like this:

    if ($request->getScheme() === 'http') {
        $urlRedirect = str_replace($request->getScheme(), 'https', $request->getUri());
        $response = new RedirectResponse($urlRedirect);
    } else {
        $response = $kernel->handle($request);
    }
    
    $response->send();
    
    $kernel->terminate($request, $response);
    

提交回复
热议问题