I have an application built on gae. I use python with webapp2 framework. I need to make 301 redirect from www.my-crazy-domain.com to my-crazy.domain.com so to eliminate www and not-www doubles in search results.
Does anybody have ready-to-use solution? Thanks for any help!
Perhaps this is a simpler way using the default get() request. Please enhance the regex if it is possible for the url to have www in places like query params.
I'v made the trick.
config.host_full contains my primary domain without www. Solution is to check request in base controller and made redirect if domain differs.
I've modified a bit @userlond answer to not require extra config value, instead I'm using regex:
A solution where you don't need to modify your main application and which also works with static files is to create a service which runs on www. For that create the following files:
www.yaml
:redirectwww.py
:dipatch.yaml
:Then deploy with
gcloud app deploy www.yaml dispatch.yaml
.