Different redirects for a subdirectory and second level subdirectories in nginx

I do not really have experience in Nginx setup, but I have a very specific problem. Our website has a blog on a subdomain – blog.example.com and we wish that example.com/blog redirects to this subdomain. I've already done this setup and it works:

location ^ ~ / blog {
rewrite ^ / blog (. *) http://blog.example.com/$1 permanent;

Now the problem is that although blog.example.com points to the blog's home page, all the post links are like this:


So, they are in a subdirectory / blog. Now we have old links posted on linkedin, etc., that will not work because something like example.com/blog/post1 will be redirected to blog.example.com/post1 and not blog.example.com/ blog / post1.

How can I make a second configuration where I can add a / blog to the redirection (blog.example.com) if there is a subdirectory like example.com/blog/post1?