Static Website Redirect HTTP to HTTPS with GCP Load Balancer with

大憨熊 提交于 2020-01-25 08:50:06

问题


I need to redirect my website from http to https, I have my static website in Google Cloud Storage Bucket pointed to Load Balance with http & https enabled.

Example:

http://ex.com = > https://ex.com
http://www.ex.com = > https://www.ex.com

The https://ex.com, https://www.ex.com both work just fine, however, I just need the http redirect so that I can reach Secure Service

Since I am having a static website I hope I can only handle this in Load Balance, Can some one help me with this.


回答1:


At this time, this is not possible via a Google HTTP Load Balancer feature. There is a feature request here.

You could add JavaScript to your pages. However, this will not guarantee HTTPS redirection. Usually, just adding this to the home page and a few key pages will get most of your traffic to HTTPS.

<script type="text/javascript">
  if (location.protocol != 'https:')
  {
   location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
  }
</script>


来源:https://stackoverflow.com/questions/58270055/static-website-redirect-http-to-https-with-gcp-load-balancer-with

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