问题原文
原帖链接 · O. Aroesti · CC BY-SA 4.0
I've recently uploaded a website on a domain via Firebase hosting. Using the domain registrar (NameCheap) I've also applied a 301 redirect rule (via NameCheap. It's called "URL redirect record" under the Host Records) so that going to "@" (for example example.com) will redirect to www.example.com.
However, I noticed that if I specify either http or https scheme like so - http[s]://example.com I get to https://example.com (even when entering http), and get an ERR_CONNECTION_REFUSED error.
What's the reason for that and how can it be fixed? Am I doing some things wrong?
I'll mention that at first the 301 rule did not work when I specified to go to https://www.example.com, and only after replacing the https with regular http did it work (although when visiting the site, I still see in the URL that it is in fact using https).
People have suggested HSTS (which is automatically added by Firebase) to be the cause for the issue, however, other websites (such as Facebook) have HSTS yet don't encounter the same problem.
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 4.0
Namecheap does not offer HTTPS for redirects. It would be better to implement the redirect at your hosting company so that they can do HTTPS for the redirect. This page has instructions about half way down for adding both www and no-www to Firebase and setting one to redirect to the other https://www.allwebtuts.com/add-a-custom-domain-on-google-firebase-hosting/
Redirecting http://example.com to either http://www.example.com or https://www.example.com should work fine. There are two reasons that you may be running into problems:
- Browser caching: Browsers aggressively cache 301 redirects. If you change a 301 redirect you need to clear your browser cache before testing again. Alternatively test with a online or command line tool. I like using the command line:
curl --head http://example.com/ - HSTS: HSTS is a directive to bypass HTTP for secuity. It is a way of saying "my site will never ever use the insecure HTTP protocol". When HSTS is enabled, browsers automatically upgrade all HTTP URLs to HTTPS after visiting your site for the first time. So if HSTS is enabled,
http://example.comwill automatically get upgraded tohttps://example.comwithout hitting your server. When you are using Namecheaps redirects without HTTPS, users will just get the connection refused error.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
