Welcome! Log In Create A New Profile

Advanced

Re: String replace on rewrite module

Alex Sergeyev
July 21, 2010 09:38AM
On Wed, 2010-07-21 at 10:32 +0600, Mikhail Mazursky wrote:
> I think there's embedded perl for that kind of stuff, but i can't help
> because i don't know perl :)

Yeah... something like this would also work

perl_set $underscored_uri 'sub { ($_ = $_[0]->uri) =~
s/(?<=.)\/(?=.*/)/_/g; $_ }'

location /something {
rewrite . $underscored_uri last;
}


1. you're ending up with perl module which is big
2. could be trickier if you have querystring to process
3. likely it'll be slower than recursive rewrites.


Alex.

p.s.
if you want to debug this in command line:

perl -Mstrict -we 'sub uri{$ARGV[0]} sub test{($_=uri()) =~
s/(?<=.)\/(?=.*\/)/_/g;$_} print
test()."\n"' /lkasld/asda/sda/sd/image.gif

will print you
/lkasld_asda_sda_sd/image.gif



_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
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: 257
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