"라라벨 https 리다이렉트 미들웨어"의 두 판 사이의 차이

(새 문서: ==개요== ;라라벨 https 리다이렉트 미들웨어 {{소스헤더|app/Http/Middleware/ForceHttps.php}} <source lang='php'> namespace App\Http\Middleware; use Closure; class F...)
 
43번째 줄: 43번째 줄:
* https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https
* https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https


[[분류: Laravel]]
[[분류: Laravel 미들웨어]]

2018년 7월 8일 (일) 16:20 판

1 개요

라라벨 https 리다이렉트 미들웨어
app/Http/Middleware/ForceHttps.php
namespace App\Http\Middleware;

use Closure;

class ForceHttps
{
	public function handle($request, Closure $next) {
		if ( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'http' ) {
			return redirect()->secure($request->getRequestUri());
		}
		return $next($request);
	}
}
app/Http/Middleware/ForceHttps.php
...
class Kernel extends HttpKernel
{
    ...
    protected $routeMiddleware = [
        'https' => \App\Http\Middleware\ForceHttps::class,
        ...
    ];
}
routes/web.php
Route::get('login','LoginController@index')->middleware('https');

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}