重定向在cakephp ssl站点路由到http不是https [英] redirect in cakephp ssl site routes to http not https

查看:200
本文介绍了重定向在cakephp ssl站点路由到http不是https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个cakephp网站,应该对所有网页使用ssl。除非我在控制器中使用重定向到http://subdomain.domain.com而不是https://subdomain.domain.com/controller/action。



我已经解决了这个问题,通过为端口80创建一个指向cakephp应用程序的虚拟主机,并将这些重写规则添加到.htaccess



RewriteCond%{HTTPS}
RewriteRule(。*) https://% {HTTP_HOST}%{REQUEST_URI} [L]



这会捕获这种情况并重定向到https,但这会给服务器带来不必要的额外流量。



此额外流量的原因是重定向功能,因为它生成错误的网址。我已经调查了重定向函数,它调用router :: url来创建实际的url。但我不能弄清楚如何或在哪里指示路由器使用https不是http。



Tim



尝试使用Jamies解决方案,网站结束了重定向循环,因为RequestHandler-> isSSL()返回false,即使请求是https。然后我发现$ _SERVER ['https']没有设置,$ _SERVER ['port']是80,而不是443如预期。



此时,我将我的ssl指令放在sites-available / default中,





SSLEngine on
SSLCertificateFile [到cert文件的路径]
SSLCertificateKeyFile [到keyfile的路径]



将ssl指令移动到子域的虚拟主机



实际上也解决了我的初始问题,因为方法Router :: url检查$ _SERVER ['https']如果设置它生成一个url以https开头,否则只是http:



我已经测试了Jameies解决方案和我自己的在.htaccess中重写规则,并且他们都按照预期在修复后工作。 / p>

Tim


I have developed a cakephp site that should use ssl for all pages. It works as expected except when I use redirect in a controller it redirects to http: //subdomain.domain.com not https: //subdomain.domain.com/controller/action.

I have solved this by creating a virtual host for port 80 pointing to the cakephp application and added these rewrite rules in .htaccess

RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

This catches this situation and redirect to https but this gives unnecessary extra traffic to the server.

The cause for this extra traffic is the redirect function as it generates wrong urls. I have looked into the redirect function and it calls router::url to create the actual url. However I am not able to figure out how or where to instruct the router to use https not http.

Tim

解决方案

I found the error it was a misconfiguration of Apache.

Trying out Jamies solution, the site ended up in a redirect loop, because RequestHandler->isSSL() returned false even if the request was https. I then discovered that the $_SERVER['https'] was not set and the $_SERVER['port'] was 80, not 443 as expected.

At that point I have placed my ssl directives in sites-available/default,

SSLEngine on
SSLCertificateFile [path to cert file]
SSLCertificateKeyFile [path to keyfile]

Moving the ssl directives to the virtual host for the subdomain resolved the issue, with redirect loops.

Actually is also solved my initial problem because the method Router::url checks for $_SERVER['https'] if set it generates a url that starts with https: otherwise just http:

I have tested both Jameies solution and my own with rewrite rules in .htaccess and they both work as expected after the fix.

Tim

这篇关于重定向在cakephp ssl站点路由到http不是https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆