I currently have a redirect loop when deploying my code on heroku but not on my local wamp server. Below is my middleware, its been properly registered. Im using laravel 5, Thanks
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redirect;
class HttpsEnforcer
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next){
if(!$request->secure())
{
return redirect()->secure($request->path());
}
return $next($request);
}
}
Request::secure() check HTTP_X_FORWARDED_PROTO header for https, make sure they are being set.
If you are behind a load balancer which listen to 443 and send traffic on 80 with HTTP_X_FORWARDED_PROTO you will need to use Request::setTrustedProxies($LB_IP)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With