1

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 requests
  • myversion-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.

Blaine Garrett
  • 1,286
  • 15
  • 23
  • 1
    The easiest way is to just detect for the appspot.com in order to perform the redirection. The best practice would actually to just use the traffic split from GCP. It is hard for a normal user to actually reach the non default version unless you are aiming for it (explicitly adding the version on the URL). What kind of tests do you want to perform or can you share an example of the search you mention with a deleted version? – rsalinas Mar 09 '20 at 14:39
  • @rsalinas I added a bit to not redirect if the HOST header ends with appspot.com It works fine for now. Here is an example search phrase to put into google "mplsart s://arts-612.appspot". Only 3 results come up with the appspot url. It used to be more and with more generic keywords. The "angular" version (top result for me) hasn't existed for years. – Blaine Garrett Mar 11 '20 at 01:09

0 Answers0