Welcome! Log In Create A New Profile

Advanced

Matching a href spec with Lua regex

June 27, 2014 10:28AM
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
Subject Author Posted

Matching a href spec with Lua regex

vamshi June 27, 2014 10:28AM

Re: Matching a href spec with Lua regex

vamshi June 27, 2014 12:57PM

Re: Matching a href spec with Lua regex

vamshi June 27, 2014 01:03PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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