Answer the question
In order to leave comments, you need to log in
Make location for nginx
Task:
Make location so that links like:
- example.com/dir1/spb/
- example.com/some/another/dir/sam/
are processed by scripts, respectively:
- example.com/dir1/?city=spb
- example .com/some/another/dir/?city=sam
The list of cities (spb, sam) is not much (4-5 pieces). They are constant and when choosing a city, the pages are always at the end of the uri.
Now I could only do rewrite, in which the converted result is displayed in the address bar of the browser. Guru, tell me how to solve this problem.
rewrite ^(.*)?/spb/$ $1?city=spb last;
- my current rewrite
Answer the question
In order to leave comments, you need to log in
location ~ /(msk|spb|sam|etc)/?$ {
## вариант 1. не уверен что это хорошая идея
#error_page 301 =200 /index.php?city=$1&$query_string;
#return 301;
## вариант 2
#try_files $uri $uri/ /index.php?city=$1&$query_string;
## вариант 3
fastcgi_pass php_fpm;
include fastcgi_params;
fastcgi_param QUERY_STRING city=$1&$query_string;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
As far as I understand you need something like this:
location ~ /dir1 {
rewrite ^/dir1/([a-z]+)/$ /dir1/?city=$1 last;
}
location ~ /some/another/dir {
rewrite ^/some/another/dir/([a-z]+)/$ /some/another/dir/?city=$1 last;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question