问题
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