[DNS & subdomains] Mapping a subdirectory to a subdomain, with 3rd-party domain and Netlify DNS

Hi community!

I’d like to request your advice on the following issue:

  • For my Netlify project, I’m using a domain name registered with a 3rd party;
  • I’m managing my DNS with Netlify – fully switched to Netlify’s name servers;
  • My Netlify project is a Nextjs app
    • The app serves some functionality in a subdirectory, such as example.com/blog
    • I want to create a subdomain like blog.example.com, that points to example.com/blog – while keeping blog.example.com in the browser’s URL bar

For doing so, based on common sense and what I gathered on the forum I understand I need to:

  • Create a DNS entry for my subdomain
  • Create a redirect config via netlify.toml to instruct Netlify’s servers to do the mapping

What I’m asking is: could you guide me in implementing the requirements I described above?

PS

I’m sorry if I’m not posting my Netlify URL as requested by the guidelines, but: this is my second attempt at creating this post, the first one was flagged by the platform’s anti-spam and had several links in it, so I suspect the links triggered the spam filter.

I’m also not posting any configs I tried, because obviously they were 100% wrong.

If you’re using Netlify DNS and connecting the subdomain to a Netlify site, you need not add any DNS records. We do that automatically for you.

But you’re right about having to add the redirect. Something like:

[[redirects]]
  force = true
  from = "/*"
  status = 200
  to = "https://other-netlify-site.netlify.app/blog/:splat"

Not sure what you’ve tried, so let us know the result with this.

Hi @hrishikesh , thanks for your reply!

So basically you’re saying that, if I redirect example.com/blog to blog.example.com with no additional config in the DNS panel, Netlify will create the blog subdomain on-demand? Because that would be awesome… :slight_smile:
I guess it’s the same principle of a branch subdomain? If you could break down the process, I’m curious to know more.

In the meantime, let me try adding a redirect :crossed_fingers:

Edit

I just realized you wrote “connecting the subdomain to a Netlify site”; so you propose fixing the problem by creating a new Netlify app and pointing the subdomain to it. Let me think… :thinking:

Update: based on this post I tried:

[[redirects]]
  force = true
  status = 200
  from = "https://menu.flop.club/*"
  to = "https://flop.club/menu/:splat"

Plus ALIAS from menu.flop.club to @ – tried also with no additional DNS record.

But it still won’t work. :frowning:

In order for Netlify to redirect URLs with the domain menu.flop.club there are two requirements:

  • the domain menu.flop.club must be added in the domain management settings for the site at Netlify
  • DNS records must be created that point menu.flop.club to Netlify

Now, if you are using Netlify DNS, the DNS records will be created automatically. However, you do need to add the domain to the site still. If it still doesn’t work after doing that, please let us know.

Hi @luke, thanks for your time!

Do you mean I need to go through the “Add a domain to Netlify DNS” process also for menu.flop.club?

I thought I just had to add the plain domain flop.club; then, I would create any subdomains directly in Netlify 's DNS management, under that domain.

Like, this is what I was trying to do (3rd record, the first 2 are created by Netlify):

Domain DNS record Resolves to
flop.club NETLIFY <my Netlify app>
www.flop.club NETLIFY <my Netlify app>
menu.flop.club ? ?

I don’t understand, please excuse my limited DNS knowledge :frowning:

No. You need to go to the domain settings on whichever site you wish to add the domain on and simply add the domain there. If you’ve created a DNS Zone for the apex domain, adding a subdomain for a site is automatically handled.

I’m sorry, I don’t see a clear way to “simply add the domain there”. Do you mean “Domain management > Add a doman alias”? But an alias is not what I need. :thinking: :question:

Look, I get it, there are thousands of posts and it’s hard to help everyone, I know you all at Netlify are doing your best, but… this is simply not helping.

I clearly described the problem, I expected a series of equally clear steps to fix it. I received various very broad and generic hints (let me be clear: I still thank you for your time!), but this is not what I need.

Maybe that’s just me! But I spent enough time trying and chasing this or that solution. Maybe the forum is not a successful customer support model.

For the record, I gave up and had to go live without subdomain, since it seems there is no easy way to implement it.

Hi, @xyz. I did give you clear steps when I wrote this:

  • the domain menu.flop.club must be added in the domain management settings for the site at Netlify

About this:

An alias is exactly what you need. The only way to add additional domains to a site after adding the primary production domain is to add domain aliases.

The steps are:

  1. Add the domain to the site (yes, as a domiain alias as that will be the only way to add it)
  2. Make certain the redirect exists as described on your November 6th post.

​Please let us know if you have tried that above and it does not work. Also, if you do want us to review the configuration, please leave the configuration in place so we can review it to troubleshoot.

Hey @luke , thanks for your advice, I’ll try whenever I get the chance.

Anyway – and I’m not judging your particular answer, but the answers to this thread as a whole – I wish someone told me clearly, from the beginning: “you need to set an alias!” :smiley:

It’d have been so much easier to fix the issue, and I could’ve published the site the way I wanted to (not to mention the time spent trying…).

Aliases might be the only way to work with additional domains, but I’m not supposed to know that, and that’s what support is for – I guess?

In any case, thanks everyone. Netlify might feel a little less awesome for me after this experience, but I’ll still think of it as an awesome service :slight_smile: