要强制HTTPS在指定的路由上运行,Laravel文档要求执行以下操作:
Route::get('foo', array('https', function()
{
return 'Must be over HTTPS';
}));现在,在我的第一个Laravel应用程序中,我一直在使用资源控制器。我不认为我会把它们用于我的第二个应用程序,继续我已经读过的东西,但是现在他们很高兴地坐在我的router.php文件中。
我想强迫我的应用程序的后台办公部分使用HTTPS。因此,我的开场白如下:
Route::resource('backoffice', array('https','BackofficeController'));拉勒维尔不喜欢这个阵列。
因此,相反,我想我应该尝试在下一个参数上:
Route::resource('backoffice', 'BackofficeController', 'https'));但是下一个参数需要一个数组。我找不到这方面的文档,但我将其转换为数组。但还是没成功。
Route::resource('backoffice', 'BackofficeController', array('https')));我甚至试过:
Route::resource('backoffice', 'BackofficeController', array('https'=>true)));然而,这也失败了。那么,如何强制资源使用https呢?
发布于 2014-01-07 12:13:23
Route::filter('forceHttps', function($req){
if (! Request::secure()) {
return Redirect::secure(Request::getRequestUri());
}
});
Route::group(['before' => 'forceHttps'], function(){
Route::resource('backoffice', 'BackofficeController');
});https://stackoverflow.com/questions/20971135
复制相似问题