Decode url in rewrite

Hey guys,

I am trying to solve a specific problem I have, but have not succeded.

Users would access a link like this:
http://mysite.com/24234234?key=3123&url=http%3A//mailee.me%3Fname%3Djohn%26code%3D123

This is a normal url with some integer params and a url encoded param. I
want nginx to automatically redirect to the url in the parameters. So I
used the following code in the nginx.conf

      location /go/click {
              set $new_url $arg_url;
              set $args '';
              rewrite ^.*$ $new_url redirect;
      }

It works beautifully. The problem is that if the encoded url also have
params, the client will receive the params encoded and it may not work
in their system.

I try to use perl code to decode the url before redirecting, but it
didnt work.

This is the code inside http context:
perl_modules perl/lib;
perl_require mailee.pm;

This is the code inside location context:
location /go/click {
perl mailee::decode;
set $new_url $arg_url;
#set $args ‘’;
rewrite ^.*$ $args redirect;
}
And the code in mailee.pm:

package mailee;
use nginx;

sub decode {
my $r = shift;
$r->args =~ s/%3D/=/g;
$r->args =~ s/%26/&/g;
$r->args =~ s/%3F/?/g;
$r->args =~ s/%3A/:/g;
return OK;
}

1;
END

But it didnt work too, because I was not able to modify $args inside the
perl function.

I am not sure if this is the best way to do it and if I am doing it
right. Do you have any other solutions?

Thanks

Posted at Nginx Forum:

Hi guys,

I solved my problem with set-misc module, now I use the set_unescape_uri
to do it.

Posted at Nginx Forum: