S
S
script882015-06-16 13:04:07
Nginx
script88, 2015-06-16 13:04:07

How to force nginx to redirect without inserting a slash before the extension?

There is a rule in which nginx redirects all requests of the form site.ru/catalog/aloha to site.ru/catalog/aloha.html

location ~ ^/catalog/([^\.]+)$ { return http://site.ru/catalog/$1.html; }

But it works correctly only when there is no slash at the end of the URL

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-06-16
@script88

location ~ ^/catalog/([^\.\/]+)/?$ {
    return http://site.ru/catalog/$1.html;
}

Replaces site.ru/catalog/aloha with site.ru/catalog/aloha.html
and site.ru/catalog/aloha/ with site.ru/catalog/aloha.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question