GitHub Pages https/www Redirect

孤者浪人 提交于 2020-05-07 11:02:40

问题


How can I get https://www.test.com to redirect to https://test.com when using GitHub pages to host a static website?

I recently enabled TLS (provided by GitHub/Lets Encrypt) for my static site by setting A records at my DNS provider (namecheap). I've also chosen to "Enforce HTTPS" option in my GitHub repository's settings, which handles redirecting requests from http://test.com to https://test.com. I have a redirect configured through my DNS provider which forwards http://www.test.com to https://test.com, but the one missing piece of the puzzle is forwarding https://www.test.com to https://test.com.

Regarding this issue, GitHub says, "If your domain has HTTPS enforcement enabled, GitHub Pages' servers will not automatically route redirects. You must configure www subdomain and root domain redirects with your domain registrar."

... and my DNS provider says, "It is not possible to set up a URL redirect in the account for the TCP port forwarding from http://www.domain.tld (uses port 80) to https://www.domain.tld (working via port 443)."

I seem to be caught in an infinite loop of the two services saying the other should provide this functionality.


回答1:


What worked for me:

  • Change your custom domain to be prefixed with www., like this:

  • Save the settings and wait until www.example.com resolves and works.

  • Remove the www. prefix and save again.

  • Wait for browser and DNS caches to invalidate.

  • All combinations should lead to https://example.com/ and no SSL error should appear.




回答2:


The simplest way would be to add a CNAME record from www.test.com to test.com. This will definitely work, I've done it a million times for my clients while I worked at a certain domain provider. I'm not sure why they didn't suggest that. Ports do not matter here as it is a domain redirect.



来源:https://stackoverflow.com/questions/54817253/github-pages-https-www-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!