161

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?

adlawson
  • 6,303
  • 1
  • 35
  • 46
contacto contact
  • 1,635
  • 2
  • 11
  • 3

15 Answers15

161

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

eudoxos
  • 18,545
  • 10
  • 61
  • 110
111

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

andreas
  • 1,483
  • 1
  • 15
  • 36
tlossen
  • 1,247
  • 1
  • 8
  • 7
  • 4
    This is a great and very useful answer to anyone using AWS. Thank you! Sweet workaround – Ken Jul 24 '14 at 21:23
  • 8
    Important to note: The bucket must be named to match the hostname being redirected to it. See http://serverfault.com/a/584714/105720 – Jordan Warbelow-Feldstein Nov 02 '15 at 22:23
  • 1
    This works as a redirect to a directory, but not to a specific page. If you redirect all requests to "www.example.com/foo/bar/baz.html" AWS will "helpfully" append a "/" to the URL, turning it into "www.example.com/foo/bar/baz.html/" and returning a 404 error. – Earl Ruby Sep 10 '19 at 23:59
  • Unfortunately this is not HTTPS compatible. I ended up making a CloudFront distribution with a redirection page. – AsTeR Sep 04 '20 at 08:49
44

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

Glen Little
  • 6,951
  • 4
  • 46
  • 68
another way
  • 457
  • 4
  • 2
  • 7
    This sounds like a useless construction, instead of making proof.proof-two.com point to www.proof-two.com/path/index.htm, You might just as well make www.roof.com point there, no need for extra DNS records. – Michiel Nov 21 '13 at 19:39
  • 19
    @Michiel It does sound like a useless construction **if** you have easy access to `proof-two.com` web servers. Sometimes big companies (and bureaucracy) make everything much more complicated than it could be. – cregox Jul 01 '14 at 11:28
  • 1
    "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" How to do this? – user2060451 Nov 17 '19 at 20:16
  • 1
    Redirection is not a function of DNS. I think that is the point here. It is an HTTP function. DNS would be used to point www.proof.com to the server that does the redirection. But in reality, it can be any server name that has the redirect rule as redirects are handled at the HTTP level by a web server. www.proof.com could be a CNAME to www.microsoft.com for example if you worked out an agreement with Microsoft to redirect from their web servers. It just has to response with a 30x redirect to www.proof-two.com/path/index.htm – DubStep Jan 13 '21 at 15:37
27

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/

You will have to use the control panel to add your redirection. It will update your DNS zone accordingly.

Let's consider you created a redirection from foo.bar.com to foo2.bar.com/path. OVH 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.

Gabriel
  • 734
  • 11
  • 26
20

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.

Udlei Nati
  • 502
  • 4
  • 12
17

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.

Alvaro Aguilar
  • 171
  • 1
  • 3
  • I have been trying this, but it does not work. All it does is redirecting users to redirect.center's site. – Geeky Guy Apr 09 '18 at 13:12
  • Can you copy your CNAME registre? Can you copy your rediriged site too? – Alvaro Aguilar May 27 '18 at 01:26
  • 1
    @Renan Make sure the source domain is present in the DNS and can be looked up by the redirect.center server; also navigating to target-domain.com.redirect.center in browser won't work. See explanation: https://github.com/udleinati/redirect.center/issues/41#issuecomment-654582255 – redfish Jul 07 '20 at 17:01
11

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.

wgrrrr
  • 186
  • 2
  • 4
6

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

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
6

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.

Karl Barker
  • 11,095
  • 3
  • 21
  • 26
5

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:

<VirtualHost *:80> SetEnv PAGE_ID "customer1" ServerName customer1.example.com ServerAlias www.customer1.com DocumentRoot /your/local/path/webserver/customer1 </VirtualHost> 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

  1. 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.

christian
  • 538
  • 5
  • 8
4

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.

4

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.

nyxz
  • 6,918
  • 9
  • 54
  • 67
  • a demonstration of a shortest possible ngxinx config file implementing this, maybe with a docker setup, would help here – masterxilo Jan 13 '22 at 16:59
1

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

gnvsale
  • 19
  • 1
-2

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

Bran Kop
  • 9
  • 1
-5

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.

Jimmie Andersson
  • 437
  • 3
  • 10