4

Namecheap and other registrars provide a way to setup HTTP 301 or 302 redirects when configuring DNS. It is a nice feature since otherwise you would need to implement it yourself. See screenshot below from Namecheap DNS configuration page.

enter image description here

Does Google Cloud DNS offer something similar?

Alex
  • 1,021
  • 3
  • 10
  • 16
  • 1
    It seems currently this record type "URL redirect record" is not available in Cloud DNS. I would suggest you submit feature-request at [public issue tracker](https://issuetracker.google.com/issues/new?component=187241). – N Singh Dec 21 '17 at 16:17
  • For other community users, feature request for this is submitted [here](https://issuetracker.google.com/70980380). – N Singh Dec 26 '17 at 15:54

4 Answers4

8

Google Cloud DNS does not provide a "URL Redirect". This isn't actually a DNS feature - it requires a webserver to serve the 302 redirect. You could implement this with a small cloud funciton like:

exports.redirectFunc = function redirectFunc (req, res) {
  res.set('Location', 'https://example.com/destination');
  res.status(302);
  res.end();
};
David
  • 9,288
  • 1
  • 20
  • 52
  • Thanks, David! I think it is just convenient to have, although I totally get your point that it is not a DNS feature. Will look into Cloud Functions. – Alex Jan 11 '18 at 23:31
  • Can you connect the Google Cloud DNS to this Google Cloud Functions? – Tom Coomer Apr 06 '20 at 08:45
  • @TomCoomer you can now by placing a serverless NEG behond an HTTP(S) Load balancer and mapping a Cloud DNS A record to the IP address of the HTTP(S) Load balanacer, see: https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts – Mark Pevec Jan 05 '22 at 23:10
6

Firebase now has a very simple setup to achieve domain redirection, just do the following:

[Your firebase project] > Console > Hosting > Connect domain

Then it should display the following:

Connect domain

sindre
  • 212
  • 2
  • 14
  • I've tried this, but unfortunately this only works for domain names and not url's, so domain.com will work but domain.com/page1 will not work. – Raj Jan 30 '22 at 20:47
  • DNS stands for "Domain Name System", and it's role is to translate the domain name of a request to an IP address. As the path is not part of the domain, this makes sense. Edit: Proxies may have the functionality you are looking for, however that may not help you in Firebase. If AppEngine is an option to you, you may consider https://cloud.google.com/appengine/docs/standard/python/how-requests-are-routed#dispatch – sindre Jan 31 '22 at 16:26
5

Although Google Cloud DNS does not have this feature, if you register your domain with Google Domains, it has a "subdomain forwarding" feature (https://support.google.com/domains/answer/6072198 that implements not only 301 / 302 redirects but also provides integrations for G Suite and other platforms that set up other types of synthetic records (https://support.google.com/domains/answer/6069273).

Google Domains runs on the same DNS serving infrastructure as Google Cloud DNS, but currently you have to choose between the "Google Domains name servers" and Google Cloud DNS name servers that serve managed zones that you can control programmatically with the Google Cloud DNS API. This means you have to choose between the Domains-specific features like synthetic records and the Cloud DNS API and GUI console. You can delegate subdomains of a domain hosted on the Google Domains name servers to specific managed zones in Cloud DNS, so it is possible to mix and match this a bit.

Alex Dupuy
  • 5,984
  • 3
  • 39
  • 35
1

Though it isn't supported directly in Cloud DNS yet (see issue: https://issuetracker.google.com/issues/70980380) a workaround can be to deploy an HTTP(S) Load Balancer and set up a redirect in the URL-map and then map the root domain to the IP address of the load balancer via an A record in Cloud DNS (and the same load balancer can be used to serve all subdomains as well without requiring any other Cloud DNS records), see: https://cloud.google.com/load-balancing/docs/url-map-concepts#url-redirects

Mark Pevec
  • 121
  • 1
  • 9