How to redirect HTTP to HTTPS in Google App Engine Flexible in PHP7 Environment?

1k Views Asked by At

According to Google docs I added the following to app.yaml file:

handlers:
- url: /.*
  script: auto
  secure: always
  redirect_http_response_code: 301

After app's deployment when I enter http://example.com no redirection to https://example.com occurs. My custom domain is verified by Google and SSL is set to Google's auto-managed feature. What am I missing?

1

There are 1 best solutions below

0
JM Gelilio On

Handlers in app.yaml were deprecated in the Google App Engine Flexible environment.

You need to force HTTPS connection according to the guide to make the browser use https instead of http by using the HTTP Strict Transport Security response header.

Example: Strict-Transport-Security: max-age=31536000; includeSubDomains

Another option is to use the custom HTTP header X-Forwarded-Proto to redirect the HTTP traffic to HTTPS.

Below is a similar issue.