N
N
Nuruzov2019-01-21 14:11:11
Nginx
Nuruzov, 2019-01-21 14:11:11

How to remove slash from URI in nginx?

I have a project. There was a task to remove multiple slashes in the url address. For example:
domain.com/ru///courses I
need to redirect
http://domain.com/ru/courses
I use docker and in the nginx container I tried different settings from Google, but I check it does not work on local

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-01-24
@dodo512

server {

    if ($request_uri ~ "//") {
        rewrite ^ $uri permanent;
    }

Works withmerge_slashes on

A
Andrey Shatokhin, 2019-01-21
@Sovigod

try something like

merge_slashes off;
if ($request_uri ~* "\/\/") {
  rewrite ^/(.*)      $scheme://$host/$1    permanent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question