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?

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: