Laravel HTTPS Redirect


(Alex Mieila) #1

Buna seara, cum pot face si eu sa imi redirectioneze automat pe HTTPS? Am SSL activat si proiectul este facut in Laravel.
Snippet:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTPS:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /index.php [L]
</IfModule>

Multumesc frumos!


(Andrei Neamțu) #2

Eu de obicei fac un middleware si il pun global. Functioneaza doar pe live ca sa nu imi afecteze pe local.

if (env('APP_ENV') === 'live') {
    if (!$request->secure()) {
        return redirect()->secure($request->getRequestUri());
    }
}
return $next($request);

(Alex Mieila) #3

Multumesc frumos. Am reusit!