M
M
MakarkaZhuk2020-02-17 11:50:55
Nginx
MakarkaZhuk, 2020-02-17 11:50:55

How to properly set up a redirect with $args?

Please help me figure out how to set up a redirect, I've already broken my head and tried a thousand combinations.

What is available: There are pagination pages of the site.ru/?q=&p=331 format
What needs to be done: Redirect to site.ru/page/331 format pages

Or just give the 404 page

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2020-02-17
@Lynn

location = / {
  if ($arg_p) {
    rewrite / /page/$arg_p? redirect;
  }
}

V
Viktor Taran, 2020-02-17
@shambler81

location / {
 if ($query_string ~ "(^|&)q\=($|&)"){
  if ($query_string ~ "(^|&)p\=([0-9]({1,})($|&)"){
    rewrite ^/$ /page/$2? redirect;
}
  }
}

but here using if is not the best idea
. Maybe it makes sense for you to put a puff redirect in 404.php.
Firstly, you will not lose speed because redirects will only work if 404, respectively, they will not load the server into an empty
one. Second, puff redirects are easier than on nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question