4
4
4upik2022-03-21 13:50:20
Nginx
4upik, 2022-03-21 13:50:20

How to write location in nginx with regular expressions at the end of the URL?

A URL like this

https://site.ru/seek?full_slug=slovo&cat=-1&page=2

you need to write a rule to fall under this URL and similar ones, slovo can be any and page=2, can be any 3,4,5, 6 etc.

I wrote this: and many other options, but they do not fit, please help

location ~* ^.+\=(2|3)$
  { try_files $uri $uri /index.php?$args;
    deny  94.143.197.111;}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-04-04
@4upik

map "$remote_addr;$args" $var {
    default 0;
    "~^94\.143\.197\.26;full_slug=[^&]*&cat=-1&page=\d*$"  1;
}

server {

    location = /seek {

        if ($var) {
            return 403;
        }

        rewrite ^ /index.php;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question