Using DNS to redirect to another URL with a path [closed]
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:
- in s3, create an empty bucket "mail.foo.com"
- under Properties -> Static Website Hosting, set "redirect all requests to: mail.google.com/a/foo.com"
- in route53, create an A record "mail.foo.com"
- 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¶m2=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
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
.