Using DNS to redirect to another URL with a path

DnsRedirect

Dns Problem Overview


I'm trying to redirect a domain to another via DNS.

I know that using IN CNAME it's posible.

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

What i need is a redirection with a path. When someone types www.proof.com, it should take them to to www.proof-two.com/path/index.htm

I know it can be done using Web Server facilities, but I need DNS redirection.

Is this possible?

Dns Solutions


Solution 1 - Dns

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

Solution 2 - Dns

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¶m2=value2

Solution 3 - Dns

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

Solution 4 - Dns

Some providers allow this but there are no "pure" DNS solutions since DNS doesn't know anything about the protocol you're using and redirects are a feature from HTTP.

For OVH, see : https://docs.ovh.com/gb/en/domains/redirect-domain-name/

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.

Solution 5 - Dns

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.

Solution 6 - Dns

Really it's easy with redirect.center

If you want create a CNAME as :

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

using redirect.center your CNAME look as canonical mode as:

www.proof.com IN CNAME www.proof-two.com.opts-slash.path.opts-slash.index.htm.redirect.center.

Now if you want redirect to https website you can add this option:

www.proof.com IN CNAME www.proof-two.com.opts-slash.path.opts-slash.index.htm.opts-https.redirect.center.

Now you can create a CNAME with the canonical mode with slash in your destiny page.

Solution 7 - Dns

To answer the original question, no, what you want is not possible using only DNS (like everyone has stated). In addition to everything mentioned already, another option is to use a URL redirection service. These types of services can enable you to configure many different types of URL redirects depending on your needs. For example:

  1. Forward a domain apex to a www. subdomain or vice versa
  2. Forward a collection of domain names to a single destination (useful for forwarding domain misspellings, old company names, etc.)
  3. Forward specific domain names to deeply linked pages (like what the OP wants)

A service that does this is EasyRedir. Full disclosure: I developed EasyRedir. There are certainly other options out there though, so I encourage you to have a look around.

Solution 8 - Dns

DNS won't redirect the path portion of a URL, so that won't be possible.

Adding

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

will direct access to www.proof.com to www.proof-two.com, where you will need to use web server config to direct users to the appropriate page.

Solution 9 - Dns

I will suppose you have this scenario: You have a unique webserver hosting various websites, each one is supposed to be presented by a separated domain:

so, the page1.html should be served by www.customer1.com and so on.

  1. create a subdomain inside the example.com dns server (your webserver): > customer1.example.com

  2. in your apache virtual server settings, map the subdomain to the directory that contain the web site for your customer #1, like this:

> ``` SetEnv PAGE_ID "customer1" ServerName customer1.example.com ServerAlias www.customer1.com DocumentRoot /your/local/path/webserver/customer1

please note the value for "ServerAlias", it is important for the next step-

at this point, you should be able to navigate to your customer1 website by browsing to:  
> customer1.example.com

  
3. In the DNS settings for customer1.com you must make a CNAME record:
> CNAME=www
LOCATION=customer1.example.com

Now, you're enabled to use: www.customer1.com.

Solution 10 - Dns

A related work concluded all the below:

Problem:

http://a.com/p1/p2.html should go to http://B.com/p1/p2.html
today, but later when configured manually/automatically, the same
http://a.com/p1/p2.html should go to http://C.com/p1/p2.html

Answers:

> DNS - converts name to IP address

Though it can do a lot of redirects, always output is IP address DNS does not understand the path or protocol part of URL, understands domain part only, that is, a.com only is converted to IP address, so when you hit http://a.com/p1/p2.html may be converted to http://152.132.121.11/p1/p2.html if you configure wrong in DNS, then you will get 152.132.121.11 (not http://152.132.121.11/p1/p2.html), so you would get some 400s error (400, 403, etc.)

> Redirection - this is http://a.com/p1/p2.html can be converted to http://b.com/p1/p2.html

All the methods like GET, POST can work, with if any headers and body, but there is a web server is involved, it could be point of failure, so scalability and availability will be key

> If you are on AWS, Route 53 -> API Gateway is possible though custom domains, internally using the Cloud front

It is possible with Amazon Certification Manager, AWS Gateway custom domains & Route53, note the us-east-1 restriction on ACM

Hope that helps someone

Solution 11 - Dns

My solution to this problem was pretty simple and straight forward. All you need is an IIS server running inside the domain.

Setup CNAME in DNS to point to the IIS server, using host names in IIS to resolve several sites on a single IIS server. I'm using the same IIS server to farm out a few sub domains to external sites.

Then in IIS setup setup redirection for that site to go to your offsite site/path, in my case it was our hosted catalog that I wanted catalog.ourdomain.com to go to. From here all the tweaking is done in IIS. Be sure to enable anonymous authentication so traffic will not be blocked.

Solution 12 - Dns

While as almost everyone stated already - it's impossible using just DNS. As a workaround I would suggest trying NGINX (http://nginx.org/en/docs/http/request_processing.html).

TL;DR - In NGINX you can create multiple virtual servers that can redirect your request based on the server name.

Ex. http://first.my-server.com redirect to place A and http://second.my-server.com redirect to place B, while both share a single physical server.

Solution 13 - Dns

You can use htaccess rewrite mod, rewrite to the subfolder if the user is requesting one specific domain not the other.

Solution 14 - Dns

Of course it is possible to redirect, with the following trick:

Create a new standard primary zone Name it same as the fictive URL that you want to redirect to Ensure that this fictive name is different than any AD DNS name Create A record with following entries:

blank.......................A............................ip-addr-2

www.........................A............................ip-addr-2

What we have here is redirection, essentially. A valid URL will resolve based on the existing DNS primary DNS zone. A fictive URL will be redirected to ip-addr-2. What is important is that the name of this entry is blank, so it will fall down to the next entry in the record and redirect to ip-addr-2

Solution 15 - Dns

Everyone has already stated this, and I just want to give you another option to a service that can help you. www.301redirect.it is a free service that can redirect your domain (with wildcard) to any destination url.

I want to add a disclosure as well: I'm the developer behind this service and there is a other options out there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncontacto contactView Question on Stackoverflow
Solution 1 - DnseudoxosView Answer on Stackoverflow
Solution 2 - DnstlossenView Answer on Stackoverflow
Solution 3 - Dnsanother wayView Answer on Stackoverflow
Solution 4 - DnsGabrielView Answer on Stackoverflow
Solution 5 - DnsUdlei NatiView Answer on Stackoverflow
Solution 6 - DnsAlvaro AguilarView Answer on Stackoverflow
Solution 7 - DnswgrrrrView Answer on Stackoverflow
Solution 8 - DnsKarl BarkerView Answer on Stackoverflow
Solution 9 - DnschristianView Answer on Stackoverflow
Solution 10 - DnsManohar Reddy PoreddyView Answer on Stackoverflow
Solution 11 - DnsDon SchaeferView Answer on Stackoverflow
Solution 12 - DnsnyxzView Answer on Stackoverflow
Solution 13 - DnsgnvsaleView Answer on Stackoverflow
Solution 14 - DnsBran KopView Answer on Stackoverflow
Solution 15 - DnsJimmie AnderssonView Answer on Stackoverflow