0

I have a middleware to rediret to HTTPS like so:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
class HttpsProtocolMiddleware
{
    public function handle($request, Closure $next)
    {
        if (!$request->secure() && app()->environment('production')) {
            dd("need to redirect");
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);
    }
}

However it is not working since if go to https://project.domain.com i get a too many redirection from the browser (and now with the dd I see the dumo even if i go to my website through HTTPS)

EDIT:
I've already tested adding

Request::setTrustedProxies([$request->getClientIp()],Request::HEADER_X_FORWARDED_ALL);

as first line, and in TrustProxies

protected $proxies = '*';

but without success

Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48

1 Answers1

0

Not really an answer to why you are experiencing what you are. But you could remove that middleware

and add

if(app()->environment('production')) {
   \Url::forceSchema('https') 
}

To your AppServiceProvider.php

Will do the same thing