Unable to redirect blog posts

I’m trying to redirect all blog posts using the following yaml:

302:
  ^/$: https://my_new_website.com/blog/$1

and what happens is when I hit: https://blog.my_old_website.com, I’m being redirected to https://my_new_website.com/blog/$1.

What I’m trying to achieve is the following.
All blog posts under https://my_new_website.com/xxx redirect to https://my_new_website.com/blog/xxx.

Thank you in advance.

It’s going to be something like this:

  ^\/([a-z0-9-]+)\/$: /blog/$1

… except that’ll cause a redirect loop. So try this?

  ^(?!\/blog\/)\/([a-z0-9-]+)\/$: /blog/$1

Is there a way to do it while making the website private to avoid duplicated content?

I’m not sure I understand your question?

We are moving our blog from https://blog.my_old_website.com to https://my_new_website.com/blog/$1.

And to avoid duplicate content issues for search engines we were thinking about disabling default ghost frontend with this: Using Ghost as a headless CMS with JAMstack

Does it make sense? I tried the redirects and disable ghost frontend but since it password protect it’s not redirecting correctly.

Or will the redirect be also handled by the search engines and not harm the SEO?