P
P
Peter2014-08-19 10:29:00
Nginx
Peter, 2014-08-19 10:29:00

Location in nginx and regex followed by redirect?

There is such a config.

location ~ /give_me/(.*)$ {
           return 301  http://site.com/page/$1;
      }

      location ~ ^/page/(.*)$  {
           proxy_pass   http://site.com/$1;
      }

When accessing site.com/give_me/car, it should redirect to site.com/page/car.
Where is the mistake? Why does it just redirect to site.com/page ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zorruch, 2014-08-19
@SeNaP

rewrite ^/give_me/(.+)$ /page/$1 permanent;
location ~ ^/page/(.*)$  {
       proxy_pass   http://site.com/$1;
 }

see - nginx.org/ru/docs/http/ngx_http_rewrite_module.html

L
Lynn "Coffee Man", 2014-08-20
@Lynn

And even better like this:

location /give_me/ {
    rewrite ^/give_me/(.+)$ /page/$1 permanent;
}
location /page/  {
    proxy_pass http://site.com/;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question