如果我复制您的规则,我似乎不会以无限重定向结束,它工作正常。
这是我用来强制 https 的 ZF 插件,而不是使用.htaccess
. 你可以试试这个,看看它是否有效:
<?php
class Application_Plugin_SslCheck extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$sslModules = array('admin', 'default'); // modules that require ssl
$module = $request->getModuleName();
if (in_array($module, $sslModules)) { // require SSL
if (APPLICATION_ENV == 'production') { // only require ssl in production mode
if (!isset($_SERVER['HTTPS']) || !$_SERVER['HTTPS']) { // if request is not secure, redirect to secure url
$request = $this->getRequest();
$url = 'https://'
. $_SERVER['HTTP_HOST']
. $request->getRequestUri();
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl($url);
}
}
}
}
}
要运行它,只需在引导程序中将其注册到前端控制器:
Zend_Controller_Front::getInstance()->registerPlugin(new Application_Plugin_SslCheck());