碰到一個問題,網站上線後,須要移除Cache-Control,就是下面這個東西php
參考網址:https://stackoverflow.com/questions/51821563/laravel-5-how-to-set-cache-control-http-header-globallylaravel
修改 RouteServiceProvider.phpweb
protected function mapWebRoutes() { Route::middleware('web') ->middleware('cache.headers:private;max_age=3600') // added this line ->namespace($this->namespace) ->group(base_path('routes/web.php')); }
修改.htaccess文件。添加以下內容
注意:須要apache開啓mod_headers,不然可能出現500錯誤apache
<IfModule mod_headers.c> Header unset Cache-Control </IfModule>
新建中間件ide
php artisan make:middleware CheckResponse
修改handle方法以下網站
public function handle($request, Closure $next) { $response = $next($request); $response->headers->remove('Cache-Control'); return $response; }
註冊中間件CheckResponse。修改kernel.phpthis
protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\CheckResponse::class, ],