Created
November 8, 2013 11:59
-
-
Save andersonfraga/7370016 to your computer and use it in GitHub Desktop.
Redirects HTTPS in Zend2
This file contains 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 | |
$request = $e->getRequest(); | |
$needHttps = (preg_match($listNeedHttps, $request->getRequestUri()) != false); | |
$isHttps = ($request->getUri()->getScheme() == 'https'); | |
$isGetMethod = ('GET' == $request->getMethod()); | |
$url = new Http($request->getUri()); | |
if ($needHttps and !$isHttps and $isGetMethod) { | |
$url->setScheme('https'); | |
$url->setPort('443'); | |
header('Location: ' . $url->normalize()->toString()); | |
exit; | |
} | |
if (!$needHttps and $isHttps) { | |
$url->setScheme('http'); | |
$url->setPort('80'); | |
header('Location: ' . $url->normalize()->toString()); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment