简体   繁体   English

Heroku https://www 重定向到 https://

[英]Heroku https://www redirect to https://

I want http://example.com , http://www.example.com and https://www.example.com redirect to https://example.com .我想要http://example.comhttp://www.example.comhttps://www.example.com重定向到https://example.com

To achieve so I have the following Namecheap dns records:为此,我有以下 Namecheap dns 记录:

CNAME @ example.com.herokudns.com   
URL REDIRECT RECORD www http://example.com

I'm also using heroku-ssl-redirect to redirect from http:// to https://我还使用heroku-ssl-redirect redirect 从 http:// 重定向到 https://

var sslRedirect = require('heroku-ssl-redirect');
var express = require('express');
var app = express();

// enable ssl redirect
app.use(sslRedirect());

What I get is that everything works as I expected besides https://www , it doesn't even load an app.我得到的是,除了https://www之外,一切都按我的预期工作,它甚至没有加载应用程序。 How can I make https://www work and redirect to https://non-www as I described above?如上所述,如何使https://www工作并重定向到https://non-www

You can't do the redirect at the DNS level for the www record, you'd need to redirect at the app.您不能在 DNS 级别为 www 记录进行重定向,您需要在应用程序中进行重定向。 The reason is that if the redirect is at your DNS provider then the client browser will connect to https www.site.com but your DNS provider will not have a valid cert for your domain and the request will be refused by your browser, assuming of course that your DNS provider has port 443 open - which they sound like they don't.原因是,如果重定向在您的 DNS 提供商处,那么客户端浏览器将连接到 https www.site.com,但您的 DNS 提供商将没有您的域的有效证书,并且您的浏览器将拒绝该请求,假设当然,您的 DNS 提供商已打开端口 443 - 他们听起来好像没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM