0

How do I direct the www. subdomain to just domain.tld without www? I'm used to firebase doing this automatically. Should I look into configuring the app.yaml, dispatch.yaml, or another method?

Mickey
  • 2,285
  • 6
  • 26
  • 37
  • Have you set the A records for the domain to point to app engine? After that, the best way to do the redirect is in your own code. – new name Dec 25 '21 at 14:13
  • @gaefan - domain.tld and www.domain.tld are setup exactly how GAE told me to set them up. When I use firebase I don't have to use my own code so I figured this could be accomplished via a configuration file? – Mickey Dec 25 '21 at 16:55
  • Please elaborate on the question to include the use case? Which GCP service is to be configured, GAE? Std/Flex? Who is the domain service Provider, is it Google Domains or third parties? – Gourav B Dec 28 '21 at 08:14

1 Answers1

-1

What you're describing is called a "naked domain", and this is described in the documentation on Custom Domains. The documentation provides the steps for mapping a custom domain to your app and updating the DNS records at your domain registrar once your service has already been mapped to your custom domain in App Engine.

To redirect your requests, you can use wildcard mappings with services in App Engine by using the dispatch.yaml file. You can find instructions on how to do that here. If you would like to know more about routing requests, you can take a look at this documentation as well which also highlights creating a dispatch file. Handlers are limited to handle URLs by executing application code, or by serving static files uploaded with the code, such as images, CSS, or JavaScript. Therefore, they cannot directly redirect one URL to another.

You would need to handle your URL by running a script that executes code that will redirect your URL. The comment shows a complete example as the script runs main.py which then redirects the URL

Priyashree Bhadra
  • 3,182
  • 6
  • 23
  • I tried using the dispatch.yaml method by adding `dispatch: -url: "*.domain.tld" service: default` but that didn't work. I think that just loads a module but keeps URL the same. If you think the answer is to redirect from www.domain.tld to domain.tld using code that is not the answer I'm looking for. – Mickey Dec 24 '21 at 15:11
  • correction: `-url: "*.dufflebagboys.net/*"` – Mickey Dec 24 '21 at 18:41
  • I would like to know your use case or how you want to redirect so that I can match your requirement with my solution. Also would like to know whether you are using App Engine Flex/Standard. I think the issue is that a redirect done at a domain level uses a CNAME record, so if www.example.com would be a CNAME to example.com. Now this works, but the request header would still show the requested domain as www.example.com as the intended target. In DNS there is no way to change this, it would have to be done at the application layer, in other words, the web server level. – Priyashree Bhadra Dec 29 '21 at 07:13
  • Given AppEngine is the recipient, it can receive the request and alter the requested DNS name. This sounds easy, but has many issues in browser behavior, etc. I would have the domain www.example.com associated with a load balancer and get the load balancer to do the permanent redirect. If that isn't an option, have the www. go to a cloud function or similar that takes the received request and return a 302 redirect response to the base domain of example.com – Priyashree Bhadra Dec 29 '21 at 07:14
  • @Mickey, can you please answer the above questions. I would like to improve my answer ( as this answer is downvoted and your question should have a valid accepted/upvoted ans) as per your requirement. If you do not elaborate on your setup and let us know how do you want to redirect, I unable to solve your issue and provide an answer that you are looking for. Kindly revert. – Priyashree Bhadra Jan 04 '22 at 06:11