Mobile app version of vmapp.org
Login or Join
Vandalay111

: Is there any way to redirect one domain to another via DNS settings keeping the path information? For example, my domain is example.com and when someone navigates to example.com/sample/page.htm,

@Vandalay111

Posted in: #301Redirect #Dns #DomainForwarding #Redirects

For example, my domain is example.com and when someone navigates to example.com/sample/page.htm, I want it to redirect to test.com/sample/page.htm.

I know that this can probably easily be done using a .htaccess file or a 404 page. However, I am looking for a solution that doesn't require me to have my DNS provider host any files for me.

I want to do this with DNS settings only, e.g.:


CNAME records
A records
301 forwarding
(any other DNS settings I'm missing)


Is there any way to do this?

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Vandalay111

4 Comments

Sorted by latest first Latest Oldest Best

 

@Rivera981

Here is the exact .htaccess rule that I use to redirect all requests from mydomain.com to mydomain.com (since the shorter is my canonical URL):

RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ mydomain.com/ [R=301,L]


That's easy enough to modify to redirect from foo.com to foobar.com, while preserving the request, the client just gets a 301 redirect to the appropriate domain.

You can't however do this 'just' with DNS, as others have said, DNS servers just resolve FQDN's to IP addresses.

10% popularity Vote Up Vote Down


 

@Angela700

As has been noted, this can not be done entirely with DNS. However, if you have the DNS for example.com refer to the same server as test.com it is very simple to configure Apache to accomplish what you wish to do. Just add the following:

<VirtualHost *:80>
ServerName example.com
Redirect permanent / test.com/ </VirtualHost>


This will rewrite any incoming link to example.com to a link for test.com, preserving the path.

Furthermore, your DNS provider does not need to host any files for you as this only relies on the web server you are already running for test.com.

10% popularity Vote Up Vote Down


 

@Cooney921

You cannot do this via DNS alone. 301 redirects are not a DNS thing. They're a webserver thing.

What you can do is point your example.com DNS entries to the same server as test.com, and set up example.com as an alias domain to test.com.

10% popularity Vote Up Vote Down


 

@Courtney195

You could make example.com/test.com resolve to the same webserver (IP) via dns (CNAME if you like) and that would work.

If you are looking to do this on a per-path basis than no. DNS is ignorant of things like URL. DNS is simply translating the host part of the url (example.com) into IP address. The web server is in charge of figuring out what (or where) the url is supposed to resolve. I believe you would need to do this at the webserver (http) level.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme