Answer the question
In order to leave comments, you need to log in
What is the correct way to use return instead of rewrite in nginx config?
Good day.
After watching the report by Igor Sysoev on HL++ https://vimeo.com/117154512 , I concluded that it is better to avoid using regular expressions and rewrites in the Nginx configuration, but I don’t know how to avoid this in the following situation, you need to rewrite the following
location /tst_
rewrite ^/tst_([0-9]+)_(.+) /?mode=feed&feed=$1&token=$2 last;
rewrite ^/tst_([0-9]+) /?mode=feed&feed=$1 last
}
location ~/tst_([0-9]+) {
return 302 http://example.ru/?mode=feed&feed=$1;
location ~/tst_([0-9]+)_(.+) {
return 302 http://example.ru/?mode=feed&feed=$1&token=$2;
}
}
Answer the question
In order to leave comments, you need to log in
You made some wrong thought.
Correct: if possible, avoid location with regular expressions.
Your first option will run faster. In addition, it is not equivalent to the second, because it does not cause a redirect.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question