How to redirect a path content to subdomain?

Hi everyone, I need help to do redirecting path content to subdomain. To help you to understand, for example that my domain is https://www.example.com/ and my website content is available in the domain path https://example.com/blog. I want to make my website content available at https://blog.example.com .

How to do this on netlify?

1 Like

hi @afnizarnur - did you read through this already?

Also, if you search the forums, you will find a variety of different posts addressing this issue.

Let us know if you can’t make it work for some reason :muscle:

Thank you for your reply!

Yes, I already read the docs and some of the posts in this forums.
But can’t find what I’m looking for.

Right now, here the netlify.toml that I create based on what I read. Also, I already add CNAME record for my subdomain on netlify domain panel.

[[redirects]]
from = “/blog/*”
to = “https://blog.example.com/:splat”
status = 200
force = true

But when I access the https://blog.example.com/ show up This site can’t be reached.

I also replied about this here but using the _redirects file format below:

https://blog.example.com/* https://example.com/blog/:splat 200

In netlify.toml format this would be:

[[redirects]]
  from = “https://blog.example.com/*”
  to = “https://example.com/blog/:splat”
  status = 200

There was a force = true in your example and not in mine. Including this may be better depending on the use case so please do include it if you prefer:

[[redirects]]
  from = “https://blog.example.com/*”
  to = “https://example.com/blog/:splat”
  status = 200
  force = true

This would match the _redirect rule with a 200! like so:

https://blog.example.com/* https://example.com/blog/:splat 200!

Please let us know if this doesn’t work as expected or if there are other questions.

1 Like

Thanks for your help!!

1 Like

Hi Luke,

This doesn’t seem to be working as expected for me. I’ve got my site living at example.com with a blog page at example.com/blog and all it’s individual posts at example.com/blog/*

I’ve added blog.example.com as a domain alias on netlify and have the following in my netlify.toml

[[redirects]]
  from = "https://blog.example.com/*"
  to = "https://example.com/blog/:splat"
  status = 200

but when I try and visit blog.example.com it just shows me the contents of example.com (url remains blog.example.com) and when I visit blog.example.com/post-1 it shows me the correct content but now the url is blog.example.com/blog/post-1 - notice blog in both the subdomain and the path

If you have any suggestions that would be great!

Hi, @aaronconway7. The site I tested this with is the only site on your account with a deploy this month.

The issue is the site javascript. If you disable javascript, the URL remains /post-1.

Only when javascript is enabled does the URL change to /blog/post-1. If you want to change this behavior the site javascript will need to be modified.

Hi Luke,

Thanks for the help. However, this doesn’t seem to work for me :frowning:

The only difference I see here is that I’m using a .dev domain. Does that make a difference?

I just get a server not found error :slight_smile :frowning:

Hi, @raivatshah, would you please send us the URL which should redirect and does not? With that information we can research issue and find out what is happening.

Thanks for your message.

My content is on https://raivat.dev/experiences and I want it to be on https://experiences.raivat.dev/

My redirect config in netlify.toml is as follows:

    [[redirects]]
       from = "https://experiences.raivat.dev/*"
       to = "https://raivat.dev/experiences/:splat"
       status = 200

raivatshah, do you have the subdomain experiences set up on raivat.dev already? that’s the thing we want to be sure of first.

1 Like

Thanks for ur message. I don’t have the subdomain setup. How may I do so?

hi there, this is a good starting point for setting up subdomains:

I`m having exact issue with my NUXT3 project.
Tried this netlify.toml script

[[redirects]]
  from = "https://stats.ro-community.com/*"
  to = "https://ro-community.com/stats/:splat"
  status = 200
  force = true

With status 200 and 301. And with a different destination URL.
The builder shows me there are “2 redirect rules processed” (+1 than default build) so the script/redirect is analyzed. However nothing happens when accessing https://stats.ro-community.com.

Further details:
I made stats.ro-community.com as an ALIAS to master/default domain (Tried to make a DNS/CNAME entry but it would not compute - 404 not found)

What i`m trying to accomplish is to split the folders into subdomains for the ease of access & SEO.

ro-community.com   ==>  /
stats.ro-community.com  ==>  /stats/
wiki.ro-community.com  ==>  /wiki/
parser.ro-community.com  ==>  /parser/

The redirect required by Next is being added before your redirect. If you’re adding the Nuxt redirect yourself (the one to /.netlify/functions/server), you need to move that below the redirect you’ve mentioned above. If you’re not adding it manually, that means Nuxt is adding that and in that case, you need to contact them as its a bug. User-configured redirects should be added before the framework’s redirects for those to work fine.

Ok. Thanks. Guess I`ll wait… Nuxt3 is too fresh and is lacking most of the documentation, including this routing part. Oh well…

I`ll use default subfolders instead of subdomains for now.
Thanks for your fast reply though.
3 days since I deployed my project on netlify and already in love with it <3

Thanks for coming back and letting us know-- glad you’re enjoying your Netlify experience so far! Happy building :rocket: