Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Created November 8, 2013 11:59
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 andersonfraga/7370016 to your computer and use it in GitHub Desktop.
Save andersonfraga/7370016 to your computer and use it in GitHub Desktop.
Redirects HTTPS in Zend2
<?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