title: Laravel Redirect Http to Https
body: <p>We use Laravel 5. For redirecting http connection to https  use Middleware HttpsProtocol.</p>
  
  <pre><code>namespace MyApp\Http\Middleware;
  
  use Closure;
  
  class HttpsProtocol {
  
      public function handle($request, Closure $next)
      {
              if (!$request-&gt;secure() &amp;&amp; env('APP_ENV') === 'prod') {
                  return redirect()-&gt;secure($request-&gt;getRequestUri());
              }
  
              return $next($request); 
      }
  }
  </code></pre>
  
  <p>In our 4 test case correctly works only 1 (last redirect). Other 3 case Middleware adds url extra index.php.</p>
  
  <p><a href="http://www.aqualink.az/index.php" rel="nofollow">http://www.aqualink.az/index.php</a> --->   <a href="https://www.aqualink.az/index.php/index.php" rel="nofollow">https://www.aqualink.az/index.php/index.php</a>
  <a href="http://aqualink.az/index.php" rel="nofollow">http://aqualink.az/index.php</a> ---> <a href="https://aqualink.az/index.php/index.php" rel="nofollow">https://aqualink.az/index.php/index.php</a>
  <a href="https://www.aqualink.az/index.php" rel="nofollow">https://www.aqualink.az/index.php</a> --->  <a href="https://www.aqualink.az/index.php/index.php" rel="nofollow">https://www.aqualink.az/index.php/index.php</a>
  <a href="https://aqualink.az/index.php" rel="nofollow">https://aqualink.az/index.php</a> ---> <a href="https://aqualink.az/index.php" rel="nofollow">https://aqualink.az/index.php</a></p>