Nginx extract a value from a variable or any string

11,779

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

map $http_referer $proxied {
    default  example.com;
    "~*(?<=url=)(?<p>[\w-.]*)(?=/)" $p;
}
Share:
11,779
silkAdmin
Author by

silkAdmin

Full stack web developer, Founder @ Nota.io

Updated on June 25, 2022

Comments

  • silkAdmin
    silkAdmin almost 2 years

    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