HTTP to HTTPS redirection on App Engine Flexible

前端 未结 3 796
傲寒
傲寒 2020-11-29 09:40

I\'ve followed the answer of this: Redirect from http to https in google cloud but it does not seem to be currently accurate any more. The anchor referenced ( https://cloud.

3条回答
  •  -上瘾入骨i
    2020-11-29 09:53

    GCP This should be as easy to just use the gcloud app cli and configure a header (Strict-Transport-Security) or redirect rule. Perhaps the push is to force us to Firebase Hosting instead which is forcing HTTPS already. For a quick solution for Single Page apps (static content) with React, Angular etc, we can use this JS snippet.

    It ignores localhost environments. You can change localhost with a host name that you would like to exclude. It then redirects using https as protocol.

     if ( location.host.indexOf("localhost") < 0 && location.protocol.toLowerCase() !== "https:"){
         const url= `https://${location.host}`;
        location.replace(url);    
      }
    

提交回复
热议问题