Last active
February 25, 2019 09:24
-
-
Save miyasinarafat/88e439cbaf8a2de1cc0e92e01229bd17 to your computer and use it in GitHub Desktop.
If you are using CloudFlare or a similar CDN you will get an infinite loop error with the %{HTTPS} solutions provided here. If you're a CloudFlare user you'll need to use this:
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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Illuminate\Support\Facades\Schema; | |
use Illuminate\Support\Facades\URL; | |
use Illuminate\Support\Facades\App; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Schema::defaultStringLength(191); | |
if (!request()->secure() && App::environment() === 'production') { | |
URL::forceScheme('https'); | |
return redirect()->secure(request()->getRequestUri()); | |
} | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
} |
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
# force https | |
RewriteEngine On | |
RewriteCond %{HTTP:X-Forwarded-Proto} =http | |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
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
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\App; | |
use Illuminate\Support\Facades\URL; | |
class HttpsProtocol | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
if (!$request->secure() && App::environment() === 'production') { | |
URL::forceScheme('https'); | |
return redirect()->secure($request->getRequestUri()); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment