Redirect subdomain to specific URL using DNS

I 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 visits this URL.

Can I do this in DNS? Or something else?

Thanks for the help!

+10
source share
2 answers

You cannot do this using DNS. DNS is used to map domain names to IP addresses. It cannot resolve the domain for a specific URI.

+15
source

Apache, .htaccess. , .

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

()

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

All Articles