File tree Expand file tree Collapse file tree 3 files changed +28
-12
lines changed
Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Kernel extends HttpKernel
2121 \Illuminate \Foundation \Http \Middleware \ValidatePostSize::class,
2222 \App \Http \Middleware \TrimStrings::class,
2323 \Illuminate \Foundation \Http \Middleware \ConvertEmptyStringsToNull::class,
24+ \App \Http \Middleware \Headers::class,
2425 ];
2526
2627 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Middleware ;
4+
5+ use Closure ;
6+ use Illuminate \Http \Request ;
7+
8+ class Headers
9+ {
10+ public function handle (Request $ request , Closure $ next )
11+ {
12+ // Check if FORCE_HTTPS is set to true
13+ if (env ('FORCE_HTTPS ' ) == 'true ' ) {
14+ \URL ::forceScheme ('https ' ); // Force HTTPS
15+ header ("Content-Security-Policy: upgrade-insecure-requests " );
16+ }
17+
18+ // Check if FORCE_ROUTE_HTTPS is set to true
19+ if (env ('FORCE_ROUTE_HTTPS ' ) == 'true ' && (!isset ($ _SERVER ['HTTPS ' ]) || $ _SERVER ['HTTPS ' ] == 'off ' )) {
20+ $ redirect_url = "https:// " . $ _SERVER ['HTTP_HOST ' ] . $ _SERVER ['REQUEST_URI ' ];
21+ header ("Location: $ redirect_url " );
22+ exit ();
23+ }
24+
25+ return $ next ($ request );
26+ }
27+ }
Original file line number Diff line number Diff line change 1- @if (env (' FORCE_HTTPS' ) == ' true' )<?php URL:: forceScheme (' https' ); header (" Content-Security-Policy: upgrade-insecure-requests" ); ? >@endif
21<html lang =" {{ config (' app.locale' ) } }" >
3-
4- {{-- Redirects to https if enabled in the advanced-config --}}
5- @if (env (' FORCE_ROUTE_HTTPS' ) == ' true' )
6- @php
7- if (! isset ($_SERVER [' HTTPS' ]) or $_SERVER [' HTTPS' ] == ' off' ) {
8- $redirect_url = " https://" . $_SERVER [' HTTP_HOST' ] . $_SERVER [' REQUEST_URI' ];
9- header (" Location: $redirect_url " );
10- exit ();
11- }
12- @endphp
13- @endif
You can’t perform that action at this time.
0 commit comments