System Administration & Network Administration
domain-name-system domain rewrite godaddy tld
Updated Mon, 12 Sep 2022 18:55:32 GMT

Point root domain to another TLD's subdomain (via DNS, not masking)


I've found some similar answers to this question but was hoping someone could clarify in case I'm misunderstanding. This is hosted on IIS 7 in ASP.NET

On my site, I have root and www domains going to my homepage:

  • example.com goes to my homepage
  • www.example.com goes to my homepage

I also have a URL redirect set up for my users:

  • user1.example.com rewrites to example.com/Page.aspx?u=user1
  • user2.example.com rewrites to example.com/Page.aspx?u=user2
  • etc.

These are all working perfectly, but I'd like to allow my users to register their own domains names to point to their own sites. They would be in control of these names and I would provide a tutorial on how to set them up. I'm pretty sure I can figure out how to get CNAME to work for the www subdomain, but I'd like to get the root URL to work also. Is this possible?

I would like:

  • userdomain1.com to point to user1.example.com
  • www.userdomain1.com to point to user1.example.com
  • userdomain2.com to point to user2.example.com

I could use domain masking but would rather not, as I'd like the domains to perform like actual domain names.

Can this be done, in any way, via DNS and/or coding? Thanks! :)




Solution

Leaving an answer here for anyone interested, since it seems like I got this working!

For the user's domain name, I will instruct them to point the A record to my website's IP address. I did this via the @ host but I imagine it could be done with the * wildcard host as well.

Then, in my Web.config file I created this entry for the IIS 7 Rewrite Module:

<rule name="UserDomain" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^(?:www\.)?example\.com$" />
    </conditions> 
    <action type="Redirect" url="http://www.example.com/Page.aspx?d={HTTP_HOST}" />
</rule>

Basically, this negative regex rule says that any domain that points to this host, which isn't the main website domain example.com, redirect to Page.aspx and pass the domain name in the querystring. This will allow me to lookup in the database just as I need to. The best part about this is that it's not domain masking, and it's not domain forwarding. It's good, clean, DNS goodness with a bit of magic to make it work.

Still need to tweak a bit, but so glad I figured this out! :)