Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DNS to redirect to another URL with a path [closed]

Tags:

redirect

dns

People also ask

Can I use DNS to redirect URL?

TLDR; No, you cannot redirect HTTP to HTTPS at the DNS level. This is something you have to configure on your web server (because it manages the protocol). If you don't have access to your web server, you will need to contact your web hosting provider.


No, what you ask is not possible. DNS is name resolution system and knows nothing about HTTP.


if you use AWS, a redirect like

mail.foo.com --> mail.google.com/a/foo.com

can be setup as follows:

  1. in s3, create an empty bucket "mail.foo.com"
  2. under Properties -> Static Website Hosting, set "redirect all requests to: mail.google.com/a/foo.com"
  3. in route53, create an A record "mail.foo.com"
  4. enable "alias", and set alias target to the "mail.foo.com" bucket

not a pure DNS solution, but it works ;)

But be aware of, the redirect skips all the URL parameters e.g.: ...?param1=value1&param2=value2


I realize this is an old thread but FWIW, incase someone else is looking for a way to do this.

While dns does not understand the path portion of the url, it will understand subdomains, so instead of:

www.proof.com IN CNAME www.proof-two.com/path/index.htm

You could use:

www.proof.com IN CNAME proof.proof-two.com

then go to wherever you host proof-two.com and set it to point proof.proof-two.com to www.proof-two.com/path/index.htm.

~ there's always more than one way to skin a cat


I have a personal project that might help you in solving this issue. It's an open source redirect solution that allows you to redirect your domain just changing your DNS settings. Link of the project: https://redirect.center/.

To redirect www.proof.com to www.proof-two.com keeping the URL parameters, just set your www DNS entry on proof.com:

www.proof.com IN CNAME www.proof-two.com.opts-uri.redirect.center.


Edit

It seems that it's my provider (OVH) who allows that kind of redirect within its infrastructure.

See : https://docs.ovh.com/gb/en/domains/redirect-domain-name/

I'm keeping the answer below for the sake of archiving, but it doesn't provide any meaningful information for other DNS providers.

Original answer

I did that using a TXT record.

To redirect foo.bar.com to foo2.bar.com/path, just add foo IN TXT "1|foo2.bar.com/path" in your bar.com DNS zone.

It also keeps the url paths and parameters. So if you try to access foo.bar.com/hello?foo=bar, you'll be redirected to foo2.bar.com/path/hello?foo=bar.