diff --git a/src/common/confs/server-http/access-lua.conf b/src/common/confs/server-http/access-lua.conf index a75f402d3..e906a2a7c 100644 --- a/src/common/confs/server-http/access-lua.conf +++ b/src/common/confs/server-http/access-lua.conf @@ -115,6 +115,7 @@ access_by_lua_block { end logger:log(NOTICE, plugin_id .. " redirect to " .. ret.redirect .. " : " .. ret.msg) redirect = ret.redirect + ctx.bw.location_header = redirect break end end diff --git a/src/common/core/errors/errors.lua b/src/common/core/errors/errors.lua index 8747ab9de..fed5a2a45 100644 --- a/src/common/core/errors/errors.lua +++ b/src/common/core/errors/errors.lua @@ -19,6 +19,14 @@ function errors:initialize(ctx) plugin.initialize(self, "errors", ctx) -- Default error texts self.default_errors = { + ["301"] = { + title = "Moved Permanently", + text = "The requested page has moved to a new url.", + }, + ["302"] = { + title = "Found", + text = "The requested page has moved temporarily to a new url.", + }, ["400"] = { title = "Bad Request", text = "The server did not understand the request.", diff --git a/src/common/core/errors/plugin.json b/src/common/core/errors/plugin.json index bd70ad5eb..235fb49e2 100644 --- a/src/common/core/errors/plugin.json +++ b/src/common/core/errors/plugin.json @@ -16,7 +16,7 @@ }, "INTERCEPTED_ERROR_CODES": { "context": "multisite", - "default": "400 401 403 404 405 413 429 500 501 502 503 504", + "default": "301 302 400 401 403 404 405 413 429 500 501 502 503 504", "help": "List of HTTP error code intercepted by BunkerWeb", "id": "intercepted-error-codes", "label": "Intercepted error codes", diff --git a/src/common/core/misc/misc.lua b/src/common/core/misc/misc.lua index 7525a23bd..e1ef0f417 100644 --- a/src/common/core/misc/misc.lua +++ b/src/common/core/misc/misc.lua @@ -46,6 +46,15 @@ function misc:access() return self:ret(true, "method " .. method .. " is not allowed", HTTP_NOT_ALLOWED) end +function misc:header() + -- Add Location header if needed + if self.ctx.bw.location_header then + ngx.header["Location"] = self.ctx.bw.location_header + return self:ret(true, "edited location header") + end + return self:ret(true, "no location header needed") +end + function misc:log_default() if self.variables["DISABLE_DEFAULT_SERVER"] == "yes" then self:set_metric("counters", "failed_default", 1) diff --git a/src/common/core/order.json b/src/common/core/order.json index ab58cda54..0e73d36b5 100644 --- a/src/common/core/order.json +++ b/src/common/core/order.json @@ -31,7 +31,7 @@ "cors", "antibot" ], - "headers": ["headers", "cors", "reverseproxy", "clientcache", "antibot"], + "headers": ["headers", "cors", "reverseproxy", "clientcache", "antibot", "misc"], "log": ["badbehavior", "bunkernet", "errors", "metrics"], "preread": [ "whitelist",