Artmetic Linux Redirect location/folder on nginx.

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.

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

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

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 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.

Leave a Reply

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

Witryna wykorzystuje Akismet, aby ograniczyć spam. Dowiedz się więcej jak przetwarzane są dane komentarzy.

Related Post