我希望我的客户部分使用https,例如注册、登录、个人详情和订单详情等。我已经设置了我的路由以包括https协议(我可以通过https访问客户部分),但我无法强制我的链接使用https:
<a class="register" href="<?php echo $this->url('customer/default', array('controller' => 'registration', 'action' => 'index'), array('scheme' => 'https', 'force_canonical' => true,)); ?>">Register</a>
我得到的是:http://myproject.dev/customer/registration
我想要的是:https://myproject.dev/customer/registration
它似乎使用了当前的方案 - 所以如果我在http上,那么url就是http,如果我在https上,那么url就是https。
如何强制$this-> url
始终使用https
方案?
'router' => array(
'routes' => array(
'customer' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/customer',
'scheme' => 'https',
'defaults' => array(
'__NAMESPACE__' => 'Customer\Controller',
'https' => true,
'controller' => 'Index',
'action' => 'index',
),
),
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'scheme' => 'https',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
[编辑]
myproject.dev
是我的本地计算机,我已更改了主机和虚拟主机文件,并设置了虚拟主机文件以接受 SSL,但这不是问题所在。
我已将路由类型更改为 Zend\Mvc\Router\Http\Scheme
并添加了方案选项,但生成的网址如下:https://myproject.dev:80/registration
,这会生成一个 SSL 连接错误
,因为它试图连接到端口 80!
当我将 child_routes
的 type
更改为 scheme
时,生成的网址为:https://myproject.dev:80/customer
[编辑]
作为临时解决方案,如果用户尝试通过非安全方案访问客户部分,我正在进行 htaccess 重定向:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/customer/?.*$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
我不喜欢这种方法,因为它不应该是必要的!
[编辑]
虽然我想让我的客户部分使用https,但我不希望网站的其余部分使用。