I have a Google App Engine project. On this project I have setup a custom domain and an SSL certificate. Therefore, I can use https://www.mysite.xxx
, http://www.mysite.xxx
and just the naked domain mysite.xxx
.
Is it possible to permanently redirect the last two to always use the secure https://
domain using the developers console or do I just have to redirect in the code?
Just in case, it is not possible to include secure handlers in app.yaml on App Engine Flexible, there isn't support for them:
The reference is from Java, but it seems to be the same for Node. I've tried to include handlers and it didn't work.
As you can see, a possible solution would be to "use X-Forwarded-Proto header to redirect http traffic". I haven't tried this because I will move to App Engine Standard, but someone has done it and explained here.
For the sake of completeness. The Java way is to set the transport guarantee to confidential like this.
You can also find this here in the documentation.
(For Node at least,) in your app.yaml, add the following:
Reference: https://cloud.google.com/appengine/docs/standard/nodejs/config/appref
So you can add "secure: always" to your yaml file
https://cloud.google.com/appengine/docs/python/config/appconfig?hl=en#Python_app_yaml_Secure_URLs
It should be done in your application. Please check this post https://stackoverflow.com/a/54289378/5293578
I've tried the following code and it worked for me (You must put this before the default request and error handler):