Redirect location/folder on nginx.

To redirect folder on nginx you cane add to the configuration file this lines:

nano /etc/nginx/sites-available/default
location ~ /<strong>folder-name</strong>/(.*)$ {
rewrite ^/<strong>folder-name</strong>/(.*)$ /new-name/$1 permanent;
}

to redirect location on nginx:

rewrite ^/folder-name/myWell-known-article /folder-name/my-new-name-article permanent;

Flags use to redirect
As earlier mentioned, there are few flags used with rewrite directive and I’d like to go through them quickly.

redirect
We call this „Temporary Redirect” or error „302 Redirect” which returns temporary redirect to new location. Usually it used for website maintenance mode.

permanent
We call this „Permanent Redirect” which returns 301 status code. Should be used carefully when we use SEO, because boot can index maintenance page.

last
It stops processing the current location folder (should be „ngx_http_rewrite_module” switch on).
For example „/en/*” skips folder /en/ and change to „/*”.

break
Break stops processing read current url (should be „ngx_http_rewrite_module” switch on). Break will be continue processing within the same location block and won’t consider the rest of location blocks.