Redirecting http to https in Google Cloud

gke ingress redirect to https
https google cloud platform
reverse proxy google cloud
google cloud https load balancer
err_ssl_version_or_cipher_mismatch google cloud load balancer
kubernetes redirect http to https
cloud run force https
google cloud url redirect

I have setup a load balancer which accepts https connections from users. The compute engines are then connected to load balancer using http connection.

I have written the following .htaccess file in the root folder:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Now, the problem is, the compute engine is always connected via http link (to the load balancer) and not https.

Thus, the .htaccess file always consider the connection to be http and not https even if the url starts with https. So, it goes in an infinite loop trying to send the user to https even when the url is https.

What should be done to redirect http to https in this case.


You should check the X-Forwarded-Proto http header. It is set by the load balancer and will have the value http or https.

HTTP to HTTPS using Google Cloud Load Balancer, Just create a second forwarding rule on the load balancer for port 80. Both will use the same backend service. If you want to forward users from http to https then​  Backup Precious Data On The Cloud. Unlimited Storage Options Don't Risk Losing Your Data. Start Today!

This took so long for me to find the answer to! Thank you so much @Lennert!

    user@host-vm:/opt/bitnami/apps/wordpress/htdocs# head -4 /opt/bitnami/apps/wordpress/conf/htaccess.conf 

    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

Google Cloud HTTPS Loadbalance, how to force http to https , We're in the process of moving all our projects on Kubernetes to make use of GCE (Google Compute Engine) ingress instead of the Nginx ingress, to be more​  We’re in the process of moving all our projects on Kubernetes to make use of GCE (Google Compute Engine) ingress instead of the Nginx ingress, to be more tightly integrated with the whole Google

For those who are using php, I've been looking for a simple way to make my project redirect any page to https in Google Cloud, and I found a simple solution. All you have to do is to add this code at the top of your php page. It has to be at the top, the F̲i̲r̲s̲t̲ L̲i̲n̲e̲ of code in your header:

if ($_SERVER['HTTPS'] == 'off') {

Google Cloud Platform: redirecting HTTP traffic to HTTPS, We appreciate all of your feedback on how critical the HTTP→HTTPS redirect feature is to your GCP apps. Our networking team has further  Better remove always use https settings from cloudflare and setup redirection rule on your web server for http to https. If using GCP HTTP(s) LB, currently there is no existing feature to redirect HTTP to HTTP(s). However, There is a feature-request in place to support this. Thanks both, see below.

Allow HTTP to redirect to HTTPS automatically – Google Cloud , How to redirect HTTP to HTTPS using GCP load balancer · linux apache google-​cloud-platform load-balancing. I'm setting up my load balancer in  Google Cloud Load Balancer (GCLB) is a software defined network load balancer available to all projects on Google Cloud Platform (GCP). For modern day web applications TLS is the standard and is typical for web frontend instances to handle any redirect of inbound HTTP requests to HTTPS.

How to redirect HTTP to HTTPS using GCP load balancer, Hello guys,. I have a angularjs environment on google cloud platform and serving it from a backend in NodeJS. How can I always redirect the HTTP URL to HTTPS​  Configure 301 Redirects for Websites on Google Cloud (Apache) If you want to redirect webpages on your website to a new location (URL), your best option is to configure a 301 redirect. In this tutorial you will learn how to properly configure 301 redirects for websites running on Google Cloud Platform.

How can I redirect HTTP to HTTPS on Google Cloud Platform , I have setup the Google Cloud Load Balancer + Google Cloud CDN. That serves traffic over HTTPS. I am wondering, how do i redirect all HTTP  Your Google Cloud Load Balancer will provide you with a 'X-Forwarded-Proto' header equal to a value of 'http' or 'https'. You would then configure you backend's ' .htacces ' file to redirect to HTTPS if the header is equal to 'http' like so:

  • .htacces file would be like:RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Hey Lennert. Thanks for the help :)
  • Thanks Mark, this helped!
  • Thanks, this helped me as well for finding the code. Just a note its working for www. as well