Answer the question
In order to leave comments, you need to log in
Nginx rewrite - convert address with parameters to NC address?
One of the sites used to have addresses with parameters like index.php?bar=foo&z=x. Now the site has been rewritten, CNC addresses, nginx is on the front.
It is necessary to register rewrites from old addresses to new ones so that the links on the Internet are not broken.
After reading, I found out that the parameter string is not passed to rewrite, but it is in the $query_string variable.
As the first option, I did this:
<pre>
if ($query_string = 'bar=foo&z=x') {
rewrite ^(.*)$ http://site.ru/bar/foo/z/x/ permanent;
}
</pre>
Answer the question
In order to leave comments, you need to log in
Regarding the addition of query_string, a quote from the documentation:
If arguments are specified in the replacement string, the previous query arguments are added after them. You can opt out of this addition by specifying a question mark at the end of the replacement string:
sysoev.ru/nginx/docs/http/ngx_http_rewrite_module.html
If arguments are specified in the replacement string, the previous query arguments are added after them. You can opt out of this addition by adding a question mark at the end of the replacement line:
rewrite ^/users/(.*)$ /show?user=$1? last;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question