S
S
Sergey Erin2020-11-02 16:27:39
Nginx
Sergey Erin, 2020-11-02 16:27:39

How to set up redirects on nginx?

Hello. I'm trying to set up redirects in such a way that the ?lang=ru get-parameters lead to mysite.com/ru/ or the city page mysite.com/subcat/?lang=ru leads to mysite.com/ru/subcat This way does not work:

location / {
        if ($arg_lang = ru) {
            return 301 $uri;
        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Erin, 2020-11-03
@artalexs

The issue was resolved as follows, if you're interested:

if ($request_uri ~* "([^\/]{3,})\?" ){set  $last_path_component  $1;}
if ($arg_lang){return 301 /$arg_lang/$last_path_component;}

I get the last $request_uri component in the first condition and then the redirect

W
wassapman72, 2020-11-02
@wassapman72

if ($arg_lang) { return 301 /$arg_lang$uri; }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question