Matching a href spec with Lua regex

vamshi nginx-forum at nginx.us
Fri Jun 27 14:28:29 UTC 2014


Hi,

I am trying to modify the response body in the following way :

If there href="http://www.google.com", I will convert it to
href="http://nginx-ip/?_url_={url-encoded-form-of www.google.com}

This is what I have in my nginx.conf

location / {
    ....
    ....
    ....

    body_filter_by_lua '
        local escUri = function (m)
            return "href=\\"http://10.0.9.44/?_url_=" ..
ngx.escape_uri("$1") .. "\\""
        end

        local newStr, n, err = ngx.re.gsub(ngx.arg[1], "href=\\"(.-)\\",
escUri, "i")
    ';
}

But I cannot see absolutely any change in the href part of the response 

Can someone help me understand why this is not matching ? What am I doing
wrong ?

-Vamshi

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251234,251234#msg-251234



More information about the nginx mailing list