diff --git a/src/lua/body_filter.lua b/src/lua/body_filter.lua index 6563aba..3acd201 100644 --- a/src/lua/body_filter.lua +++ b/src/lua/body_filter.lua @@ -27,7 +27,7 @@ local function rewrite_body(body) -- Rewrite links for assets and outbound links to other mirrored sites local pool_map = ngx.ctx.jasima_pool_map if pool_map then - body = body:gsub("//([a-zA-Z0-9%.%-]+%.[a-zA-Z0-9]+)/", utils.get_mirror) + body = body:gsub("//([%a%d%.-]+%.[%a%d-]+)/+", utils.get_mirror) end -- Add Matomo tracking code if ngx.ctx.jasima_config.matomo_site_id then @@ -37,8 +37,8 @@ local function rewrite_body(body) -- Handle first party Tealium installations if ngx.ctx.jasima_host_tealium then local escaped_host = ngx.ctx.jasima_host_tealium:gsub("%.", "%%.") - body = body:gsub("(https:)??//" .. escaped_host .. "/", "/utag/" .. ngx.ctx.jasima_config.first_party_tealium.account .. "/") - body = body:gsub("//tags.tiqcdn.com/", "/") + body = body:gsub("https://" .. escaped_host .. "/+", "/utag/" .. ngx.ctx.jasima_config.first_party_tealium.account .. "/") + body = body:gsub("//tags.tiqcdn.com/+", "/") if ngx.var.jasima_host_connect == "tags.tiqcdn.com" and ngx.ctx.jasima_host_adobe then body, count = body:gsub([[return"http"%+%(a%.ssl%?"s":""%)%+"://"%+b%+"/b/ss/]], [[return"/b/ss/]]) ngx.log(ngx.DEBUG, "Performing rewrite for Adobe Analytics in Tealium tag " .. count) @@ -47,7 +47,7 @@ local function rewrite_body(body) -- Handle first party Adobe Analytics if ngx.ctx.jasima_host_adobe then local escaped_host = ngx.ctx.jasima_host_adobe:gsub("%.", "%%.") - body = body:gsub("(https:)??//" .. escaped_host .. "/", "/") + body = body:gsub("https://" .. escaped_host .. "/+", "/") end return body end diff --git a/src/lua/header_filter.lua b/src/lua/header_filter.lua index a370bc7..295d395 100644 --- a/src/lua/header_filter.lua +++ b/src/lua/header_filter.lua @@ -23,6 +23,6 @@ end if ngx.header["Location"] then if ngx.ctx.jasima_pool_map then local location = ngx.header["Location"] - ngx.header["Location"] = location:gsub("//([a-zA-Z0-9%.%-]+%.[a-zA-Z0-9]+)/", utils.get_mirror) + ngx.header["Location"] = location:gsub("//([%a%d%.-]+%.[%a%d-]+)/+", utils.get_mirror) end end