E
E
EvilDev2021-06-02 02:11:04
Nginx
EvilDev, 2021-06-02 02:11:04

How to make redirect in nginx?

Need to make redirects:
Yes
/catalog/search/?q=Stray
Need
/catalog/?search=Stray

Tried
#location /catalog/search/ {
# rewrite \?q=(.*)$ /catalog/?search=$1 last ;
#}
#location /catalog/search/ {
# rewrite ^ /catalog/\?search=$1 last;
#}
#rewrite ^/catalog/search/(.+)$ /catalog/?search=$1 permanent;
Does not work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-06-02
@EvilDev

if ($request_uri ~ "^/catalog/search/\?q=(.*)") {
    return 301 /catalog/?search=$1;
}

location = /catalog/search/ {
    if ($args ~ "^q=(.*)") {
        return 301 /catalog/?search=$1;
    }
}

location = /catalog/search/ {
    return 301 /catalog/?search=$arg_q;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question