Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect a subdomain to a specific url using DNS

I've redirected my domain http://domain1.com to http://domain2.com using a 301 redirect.

Now i would like to redirect subdomain.domain1.com to domain2.com/folder when the user arrives on that url.

Can I do this in dns? Or in some other way?

Thank you for your help!

like image 972
cmplieger Avatar asked Sep 08 '11 20:09

cmplieger


2 Answers

You can not do this with DNS. DNS is used to map domain names to IP address(es). It can not resolve a domain to a specific URI.

like image 55
Karmic Coder Avatar answered Nov 17 '22 12:11

Karmic Coder


If you use an Apache server you can achieve this using .htaccess file. You can try adding following lines to the file and see whether it works.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?subdomain.domain1\.com$
RewriteRule ^(.*)$ http://www.domain2.net/subfolder$1

(or)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.domain1\.com$
RewriteRule ^(.*)$ www.domain2.net/subfolder$1  
like image 23
Rajesh Durai Avatar answered Nov 17 '22 12:11

Rajesh Durai