I have implemented some express middleware on my node application to detect if the host does not match the canonical domain and 301 redirects accordingly. The app.yaml is set to secure:always, so this mostly redirects naked (missing www
) and aliased domains to my canonical domain.
This works well, but I'd ideally like to prevent redirect on non-default version for a service. This is mostly for smoke testing before migrating traffic.
Investigating the values of the HOST header, I receive:
0.myversion.myproject.appspot.com
on all /_ah/start, etc requestsmyversion-dot-myproject.appspot.com
for non domain requests,www.mydomain.com
domain when using the domain.
I'm leaning towards just detecting if the HOST ends in appspot.com and calling it a day. However, it would be nice if I could detect if the request is for a version that is non-default and not redirect. Is there a header I am not seeing or some other best practice?
Bonus: It would be neat to detect if the version doesn't actually exist and also redirect. I've found Google search sometimes shows deleated-dot-myproject.appspot.com
results and I'd love to redirect those to the canonical domain as well in the ideal situation.
Thanks in advance.