Reputation: 574
I have a domain (let's say) example.com and I want to serve its content (mainly static files - client side app) from the naked domain. I also want to accept subdomains, so they will not end in error because of DNS or 404. It is common for users to put www in front of the domain (for whatever reason).
I did set up the custom domains in appengine console, the naked and also the * (wildcard). It shows what DNS records I need to have, so I set them up too... exactly the same, A/AAAA records pointing to appengine IPs and * CNAME to appengine alias (googlehosted).
I have read how it behaves by default on https://cloud.google.com/appengine/docs/domain?csw=1 and I would like to change it a bit. Now the page is accessible from all the domains example.com, www.example.com, blog.example.com etc.
What I would like is to redirect all request going to anything else than the naked domain to the naked domain without adding any script handler.
With Apache and modrewrite the solution is easy, as it has a RewriteCond %{HTTP_HOST}
and RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
... but is it possible to do this with app.yaml? I couldn't find it at https://cloud.google.com/appengine/docs/python/config/appconfig.
I don't want to redirect in javascript (doesn't work for images, css, etc) and I don't like the idea of script handler for all the files, as it IMHO needs to have some performance penalty.
Upvotes: 1
Views: 260
Reputation: 3591
So, you seem to want to have any subdomains redirect to your naked domain, without needing to write a handler. While you could use a CNAME wildcard on subdomains in your zone file to direct to "@", the naked domain, this is inadvisable since not every provider supports it. You can read more about this strange edge case in an otherwise very standardized system like DNS here.
While you could use a dispatch file (python doc, but other languages have similar) to catch subdomain requests and send them to a special, simplified "3xx redirect to naked domain" module, short of hosting a GCE instance frontend running Apache, you won't be able to change the user's address bar with the CNAME method, although they will be directed to the IP addresses (A/AAAA records) specified at the apex level of your zonefile ("naked domain"), unless you implement such a module. Apache rewrite rules send exactly such HTTP 3xx responses which redirect the browser to change its URL and request the specified URL (in this case, your naked domain).
Upvotes: 0