Zend Framework 1 force HTTPS


Zend Framework 1 force HTTPS

如何使用Zend Framework 1、Zend_View_Helper_Url和请求对象强制HTTPS?

我得到了这个,但正在寻找一种不插入_SERVER变量的ZF1方式。。。

if (!$this->getRequest()->isSecure()) {
    $this->redirect(
        'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']
    );
}

请不要建议.htaccess解决方案。有太多的问题要求Zend代码回答mod_rewrite建议。

我知道你可以将options传递给URL/redirect助手,但我不确定它是如何完成的。

伪码:

$this->redirect(array('useHttps' => true), $this->getRequest()->getRequestUri());

尝试serverUrl((助手

// Current server URL in the example is: http://www.example.com/foo.html
echo $this->serverUrl();
// Output: http://www.example.com
echo $this->serverUrl(true);
// Output: http://www.example.com/foo.html
echo $this->serverUrl('/foo/bar');
// Output: http://www.example.com/foo/bar
echo $this->serverUrl()->getHost();
// Output: www.example.com
echo $this->serverUrl()->getScheme();
// Output: http
$this->serverUrl()->setHost('www.foo.com');
$this->serverUrl()->setScheme('https');
echo $this->serverUrl();
// Output: https://www.foo.com

http://framework.zend.com/manual/1.12/en/zend.view.helpers.html

    protected function _initForceSSL() {
      if($_SERVER['SERVER_PORT'] != '443') {
         header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         exit();
       }
    }

将此函数放入引导文件