Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Redirect Http to Https

We use Laravel 5. For redirecting http connection to https use Middleware HttpsProtocol.

namespace MyApp\Http\Middleware;

use Closure;

class HttpsProtocol {

    public function handle($request, Closure $next)
    {
            if (!$request->secure() && env('APP_ENV') === 'prod') {
                return redirect()->secure($request->getRequestUri());
            }

            return $next($request); 
    }
}

In our 4 test case correctly works only 1 (last redirect). Other 3 case Middleware adds url extra index.php.

http://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php http://aqualink.az/index.php ---> https://aqualink.az/index.php/index.php https://www.aqualink.az/index.php ---> https://www.aqualink.az/index.php/index.php https://aqualink.az/index.php ---> https://aqualink.az/index.php

like image 905
Ramin Darvishov Avatar asked Dec 25 '22 02:12

Ramin Darvishov


1 Answers

I solved with htaccess

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
like image 139
Ramin Darvishov Avatar answered Dec 26 '22 17:12

Ramin Darvishov