T
T
transcend2018-06-21 11:24:00
Nginx
transcend, 2018-06-21 11:24:00

How to make a redirect in NGINX with parameters?

There is a mobile version of the site located on the subdomain m.site.ru
Desktop, respectively, on site.ru It is
necessary to make a 301 redirect from the mobile version to the desktop.
The section has the address https://m.site.ru/read/X, where X is the article number, there are many articles.
I don’t understand how to make a rule so that there is automatically a 301 redirect both from
https://m.site.ru/read to https://site.ru/read
and from https://m.site.ru/read/ X to https://site.ru/read/X
There is a simple redirect from m.site.ru/read -> site.ru/read. It remains to improve this rule so that the redirect works on article numbers as well

location  = /read {
        return 301 https://site.ru/read;
}

Please help :-)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OnYourLips, 2018-06-21
@OnYourLips

location  = /read {
        return 301 https://site.ru/read$request_uri;
}

K
Kirill Maslov, 2018-06-28
@bziker

You need to remove the equal sign, this is how it should work:

location /read {
    return 301 https://site.ru$request_uri;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question