A
A
AnjeyTsibylskij2018-05-05 18:16:51
Nginx
AnjeyTsibylskij, 2018-05-05 18:16:51

How to make Nginx redirect?

How to make Nginx redirect from site.com/%40userto site.com/@user
I write the following condition , but there is no redirect. It seems to me that this is because of the % sign , it needs to be escaped somehow, because when I remove it and leave it just 40 , the redirect works for I tried to look for how to escape % , but there is nothing sensible. Maybe I'm digging in the wrong direction? rewrite ^/%40(.*)$ /@$1 permanent; rewrite ^/40(.*)$ /@$1 permanent;site.com/40user

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-05-23
@AnjeyTsibylskij

locationand rewritefor matching use the request URI in a normalized form, i.e. already after decoding the text given in the form %XX.
In its original form, the request can be found in $request_uri. There it will be entirely (with arguments).

if ($request_uri ~ "^/%40(.*)$") {
    return 301 /@$1;
}

K
ky0, 2018-05-05
@ky0

Dig towards Urlencode, IMHO.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question