Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx extract a value from a variable or any string

Tags:

redirect

nginx

Is there an alternative of using If to extract a value from a variable in Nginx config files?

I.e

    if ($http_referer ~* (?<=url=)([\w-.]*)(?=/) ){
            set $proxied $1;
            rewrite (?<=/)(.+\.(css|jpg|png|gif|js)) http://$proxied/$1 redirect;

     }

Thanks

like image 317
silkAdmin Avatar asked Sep 17 '12 12:09

silkAdmin


1 Answers

Yes. http://nginx.org/r/map

map $http_referer $proxied {
    default  example.com;
    "~*(?<=url=)(?<p>[\w-.]*)(?=/)" $p;
}
like image 71
VBart Avatar answered Sep 28 '22 08:09

VBart