T
T
tigra2018-10-01 16:54:37
Nginx
tigra, 2018-10-01 16:54:37

How to make a redirect in nginx?

all addresses that end in /index should be redirected to the same URL only without index, for example:
site.ru/new/items/index ->> site.ru/new/items
site.ru/new/categories/index ->> site.ru/new/categories
I only had enough for

location ~* /(index)(/?).* {
     rewrite  ^ <что то тут надо написать> permanent;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-10-01
@tigroid3

You can put it directly in the server block without adding location.

rewrite ^/index$ / permanent;
rewrite ^(.+)/index$ $1 permanent;

Can be combined into one rule.
rewrite ^/((.+)/)?index$ /$2 permanent;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question