M
M
Marcel Markhabulin2013-04-23 00:56:43
Nginx
Marcel Markhabulin, 2013-04-23 00:56:43

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

3 answer(s)
A
avalak, 2013-04-23
@milar

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;
}

S
sirko_el, 2013-04-23
@sirko_el

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;
}

Restrictions:
1. The config will only work with two urls /dir1/spb/ and /some/another/dir/sam/ with trailing slashes.
2. City abbreviations must contain only lowercase letters.
3. Each of the directories /dir1/ and /some/another/dir/ should contain index files.

J
JustAMan, 2013-04-23
@JustAMan

proxy_pass instead of (together - underline as necessary) rewrite will not work? I can’t figure out how to use it right away, but you can think, it seems to me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question