Welcome! Log In Create A New Profile

Advanced

Re: String replace on rewrite module

July 20, 2010 10:57AM
Alex Sergeyev Wrote:
-------------------------------------------------------
> You can also build recursive redirects like in my
> example, without break
> to make nginx repeat cycle of rewrites again, up
> to 10 times.

Thanks a lot, Alex,

Your comments enlightened my path!

Here is the working configuration:


[code]
location ~ ^/(.*)/([^/]+)/image/([^/]*)$ {
set $part1 $1;
set $part2 $2;
set $filename $3;
rewrite ^.*$ /${part1}_$part2/image/$filename last;
}

location ~ ^/([^/]+)/image/([^/]*)$ {
set $folder $1;
set $filename $2;
rewrite ^.*$ /image/$folder/$filename break;
}
[/code]


The first location directive is recursive, and keeps joining the paths, replacing "/" by "_" on each iteration.

The second location directive is the final one. When all path pieces are already joined, it does the final rewrite.

Cool!


Anyway, a "string replace" function for the rewrite module remains a wish as a [i]feature request[/i]...

Thanks!
Subject Author Posted

String replace on rewrite module

jbruni July 20, 2010 09:22AM

Re: String replace on rewrite module

Alex Sergeyev July 20, 2010 09:38AM

Re: String replace on rewrite module

Alex Sergeyev July 20, 2010 09:48AM

Re: String replace on rewrite module

jbruni July 20, 2010 10:57AM

Re: String replace on rewrite module

Mikhail Mazursky July 21, 2010 12:36AM

Re: String replace on rewrite module

Alex Sergeyev July 21, 2010 09:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 288
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