Welcome! Log In Create A New Profile

Advanced

Re: rewrite location in the middle of the path

Maxim Dounin
November 30, 2012 12:16PM
Hello!

On Fri, Nov 30, 2012 at 11:06:39AM -0500, nrsk wrote:

> Здравствуйте!
>
> Столкнулась с задачей: необходимо преобразовать url типа
> /my-context/id/param1,param2,paramN в url типа
> /dev/folder/id_param1,param2,paramN. Id может быть только числом.
> Попробовала написать rewrite для данного преобразования.
> location /my-context/([0-9]+)/(.*)$ {
> rewrite /dev/folder/$1_$2/ permanent;
> }
> Итоговую строку получила в виде /dev/folder/id/param1,... etc.
> В чем может быть проблема с заменой символов "/" на "_" ?

Я вижу как минимум три проблемы:

1. В location написано регулярное выражение, но модификатора "~"
не стоит. В результате location будет интерпретироваться как
обычная строка.

2. В директиве rewrite пропущено регулярное выражение. Синтаксис
директивы rewrite выглядит так:

rewrite regex замена [флаг];

Подробности см. http://nginx.org/r/rewrite/ru.

3. Кроме того, надо учитывать, что $1 и т.п. берутся из последнего
совпавшего регулярного выражения, т.е. в случае директивы rewrite -
из регулярного выражения в этом самом rewrite'е.

Правильно как-то так:

location /my-context/ {
rewrite ^/my-context/([0-9]+)/(.*)$ /dev/folder/$1_$2/ permanent;
}


--
Maxim Dounin
http://nginx.com/support.html

_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

rewrite location in the middle of the path

nrsk November 30, 2012 11:06AM

Re: rewrite location in the middle of the path

Peter Vereshagin November 30, 2012 11:44AM

Re: rewrite location in the middle of the path

Maxim Dounin November 30, 2012 12:16PM

Re: rewrite location in the middle of the path

nrsk November 30, 2012 02:55PM

Re: rewrite location in the middle of the path

Peter Vereshagin December 01, 2012 03:30PM

Re: rewrite location in the middle of the path

nrsk December 03, 2012 02:46AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready