有没有办法按照标题中提到的去做?目前,无论我们是否输入 https://www.url.com,所有 URL 请求都会转到 http://www.url.com
我的代码是引导程序.php是:
class Core_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath(APPLICATION_PATH . '/modules/core/views/helpers','Core_View_Helper');
//$view->controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$view->doctype('XHTML1_TRANSITIONAL');
// setting content type and character set
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
->appendHttpEquiv('X-UA-Compatible', 'IE=7')
->appendHttpEquiv('X-UA-Compatible', 'IE=EmulateIE7');
$frontend= array(
'lifetime' => 7200,
'automatic_serialization' => true
);
$backend= array(
'cache_dir' => APPLICATION_PATH . '/../data/cache',
);
$cache = Zend_Cache::factory(
'core',
'File',
$frontend,
$backend
);
Zend_Registry::set('cache',$cache);
}
protected function _initRoutes()
{
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');
$router = $front->getRouter();
$route['page'] = new Zend_Controller_Router_Route_Regex(
'([^'.]+)'.html',
array(
'module' => 'cms',
'controller' => 'page',
'action' => 'view'
)
);
$router->addRoute('page', $route['page']);
}
}
用于重定向的 htAccess 是无用的,因为它会创建一个间接循环。似乎所有带有https的网址都将重定向到http。有没有办法阻止这种情况?
尝试更新 .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
请注意,在应用程序的根目录下应该只有一个 htaccess。检查您的公用文件夹并删除 .htaccess (如果存在)