Welcome! Log In Create A New Profile

Advanced

Re: How to do substitions (like perl s/// operator) in rewrites?

January 11, 2010 04:18PM
Issue solved!

I followed Maxim's advice and compiled embedded perl in. However, I found the configuration not as trivial as Maxim claimed: embedded perl documentation is scarce and examples are rare.

The following configuration solved it for me and it may serve as an example for others of using the map module together with embedded perl:
[code]
http {
...

# use the map module to include a list with keys and corresponding article-ids
map $uri $old-class-url {
include /etc/nginx/rewrites/old-class-urls.txt; # (see the first post for a sample of the contents)
}

# lower case uri's file name part and remove dashes with perl. Return result to nginx variable $old_uri
perl_set $old_uri 'sub {
my $r = shift;
my $uri = $r->uri;
if($uri =~ /\/([^\/]+)\.htm$/) {
$uri = lc($1);
$uri =~ s/-//g;
}
return $uri;
}';
...
server {
...
location ~* ^/News/Articlepage-News/.*htm$ {
# rewrite $uri to variable $old_uri
rewrite ^ $old_uri ;
# return the article-id in the rewrite if $uri appears in the map
if ($old-class-url) {
rewrite ^ /old-class-url.php?articleid=$old-class-url permanent;
}
}
...
}
}
[/code]

I welcome any suggestion for a simpler solution.

Bart Schipper
Subject Author Posted

How to do substitions (like perl s/// operator) in rewrites?

bartschipper January 10, 2010 09:08AM

Re: How to do substitions (like perl s/// operator) in rewrites?

Maxim Dounin January 10, 2010 09:32AM

Re: How to do substitions (like perl s/// operator) in rewrites?

dobe January 10, 2010 12:09PM

Re: How to do substitions (like perl s/// operator) in rewrites?

bartschipper January 11, 2010 03:28AM

Re: How to do substitions (like perl s/// operator) in rewrites?

bartschipper January 11, 2010 04:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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