Rewrite the HTTP response Location header
You can use the content rewriting feature to rewrite the HTTP response Location header. If you are more comfortable using Lua string substitution, you can write a script to get the results you want. The following example rewrites the HTTP response Location header.
Rewrite the HTTP body in the response:
-- REWRITE_LOCATION_HTTP_TO_HTTPS.lua
-- Replace "http://" with "https://" in the Location response header.
when HTTP_RESPONSE {
local loc = HTTP:header_get_value("Location")
if loc and loc ~= "" then
debug("Location header found: %s\n", loc)
-- only rewrite if it starts with "http://"
if string.find(loc, "^http://") then
local newloc = string.gsub(loc, "^http://", "https://")
debug("Location rewrite: %s -> %s\n", loc, newloc)
HTTP:header_replace("Location", newloc)
end
else
debug("Location header not found.\n")
end
}