Can a CNAME DNS record point to a subdirectory

Can a DNS record point to an address like my.domain.com/subdir1


DNS records only map IP addresses to hostnames so in a word, no

You could, however, use a hostname configuration in your web server to serve a subdirectory when a request comes in. Like having something.domain.com redirect/equate to somethingelse.domain.com/downhere. That would depend on your web server software, not DNS.


CNAME records are part of the Domain Name System, the naming system for the internet. Their only purpose is to translate host names, like www.example.com into IP addresses. You can't attach folder names or queries to a CNAME. To be precise, CNAME resolve into other names, which themselves can be A-Records pointing to IP addresses or other CNAME records.

Your example my.domain.com/subdir1 or better http://my.domain.com/subdir1 A URI, a Uniform Resource Identifier which is used todentify or name a resource on the Internet - in your case a HTTP resource.

So, a workaround could be to define a CNAME to a different host header, which redirects to your folder using the HTTP status response 301 ("moved permanently"):

-> Browser requests subdir1.domain.com 
-> Server sends a HTTP status code 301 to the browser:
   REDIRECT my.domain.com/subdir1

All web servers and web programming languages provide commands for these types of redirects.