Nginx: Rewrite from base domain to a sub directory

location = / {
    rewrite ^ http://site.com/blog/ redirect;
}

This'll just do requests specifically for the root. If you need to catch everything (redirect http://site.com/somearticle/something.html to http://site.com/blog/somearticle/something.html), then you'll need something more involved:

location /blog/ {
    # Empty; this is just here to avoid redirecting for this location,
    # though you might already have some config in a block like this.
}
location / {
    rewrite ^/(.*)$ http://site.com/blog/$1 redirect;
}

try this instead:

location = / {
      return 301 /blog/;
 }

The key here is '=' symbol.

Tags:

Nginx

Rewrite