-
-
Save azazqadir/9e413dbfbb2e610fac66cea6f0cdbba8 to your computer and use it in GitHub Desktop.
Enable SSL on Laravel Website and Enable Force HTTPS Redirect: https://www.cloudways.com/blog/how-to-setup-https-ssl-certificates-on-laravel-5/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
Then, apply this middleware to every request adding, setting the rule at Kernel.php file, like so: | |
protected $middleware = [ | |
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', | |
'Illuminate\Cookie\Middleware\EncryptCookies', | |
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', | |
'Illuminate\Session\Middleware\StartSession', | |
'Illuminate\View\Middleware\ShareErrorsFromSession', | |
// appending custom middleware | |
'MyApp\Http\Middleware\HttpsProtocol' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment