Skip to content

Instantly share code, notes, and snippets.

@chihirokaasan
Last active September 6, 2017 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihirokaasan/0cc8d74e1c5893ce034ffaf22a78a326 to your computer and use it in GitHub Desktop.
Save chihirokaasan/0cc8d74e1c5893ce034ffaf22a78a326 to your computer and use it in GitHub Desktop.
CakePHP3 redirect to SSL
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);
}
public function beforeFilter(Event $event)
{
$this->Security->requireSecure();
}
public function forceSSL()
{
return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment