S
S
Sergey Khlopov2021-08-06 15:28:18
Nginx
Sergey Khlopov, 2021-08-06 15:28:18

How to make a redirect from slash to without slash when url with parameters?

Hello, please tell me, you need to make a 301 redirect from a slash to without a slash.
To do this, I write in the config like this:

location ~ ^(.+)/$ {
     return  301  $1$is_args$args;
}

And I also tried this: But this regular expression also includes such URLs:
rewrite ^/(.*)/$ /$1 permanent;

  • https://domain.com/test/?page=4
  • https://domain.com/test/?page=5&view=grid

that is, the redirect occurs to without a slash: .
  • https://domain.com/test?page=4
  • https://domain.com/test?page=5&view=grid

And I would like that such URLs with a slash as in the example do not redirect, can this be done in the config?
Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question