Nginx rewrite rule to remove path node

Try this one:

location /blog {
 rewrite ^/blog(/.*)$ $1 last;
}

If you need this for more than one site you can't just put it higher in hierarchy because "location" clause can't be specified globally, only for specific site. If you need to add this clause for two sites or more you can put it another config file and then just "include" it in each site that needs this redirection.


Depending where you define the rewrite directive you have two ways to implement it:

A. In the server context

server {
    ...
    rewrite ^/blog(/.*)$ $1 last;
    return 403;
    ...
}

B. In the location context

location /blog {
    rewrite ^/blog(/.*)$ $1 break;
}

Teo, why did you change the flag to break?* Because, if this directive is put inside of a location context, the last flag might make nginx to run 10 cycles and return the 500 error.