M
M
maksimaels2015-02-24 10:46:28
Nginx
maksimaels, 2015-02-24 10:46:28

Nginx rewrite - how to get the value of multiple variables?

For the third day I have been trying to understand the rules of rewriting and how to write what, my head no longer cooks. Tell me how to get the values ​​123 and 456
from an address like example.com/123/456.
in php script you need to get data by analogy with example.com/index.php?a=123&b=456. The names of the variables (a and b) are constant, they should not be passed.
With one variable, everything is clear - I did try_files $uri $uri/ /index.php?a=$uri;
for two it is necessary to do a rewrite?
Or is it necessary to implement and process the $_GET['a'] value by means of the script itself, which now gives /123/456 (i.e. the entire line)

location / {	
                try_files $uri $uri/ /index.php?a=$uri;
                }

location ~ .php$ {
    include             /etc/nginx/conf.d/fastcgi_params.conf;		
               .... другие параметры...			
                }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ShamblerR, 2015-02-24
@ShamblerR

1. (x)(y ) nobody canceled $1$2 and so on.
2. SET also works. what is the problem ?

if ($host ~* ^(www\.)(.+)) {
                set $HBW $2;
                root   /var/www/$HBW/web;

Although all this is very strange, usually it is done on the php side.
Describe what you want to get as a result of a specific task, it is not yet clear why to do this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question