W
W
wargych2019-06-07 12:31:04
Nginx
wargych, 2019-06-07 12:31:04

How to catch a WordPress search query on nginx and route it via location?

The essence of the question is as follows - nginx is configured with the following routing:

location = / {
            proxy_pass http://localhost:9000;
            ...
        }

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

Accordingly, requests that include only the domain are processed on a self-written go-server, the rest are redirected to wordpress.
The problem is that wordpress search requests are sent to a url like domain.ru/?s=... and are redirected to the goroutine server.
Question - how to catch get requests like /?s=... at the nginx level and redirect to wordpress?
I think that this can be done through if ($args ~ ^get=s$ ) or something like that, but I have not been able to compile a working config yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2019-06-07
@wargych

location = / {
  if ($arg_s) {
    rewrite ^ /index.php last;
  }
  proxy_pass http://localhost:9000;
  ...
}

But it would be better to just use a different address right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question