apisix/plugins/custom-redirect.lua
2025-06-16 13:40:33 +08:00

29 lines
574 B
Lua

local core = require("apisix.core")
local ngx = ngx
local plugin_name = "custom-redirect"
local schema = {
type = "object",
properties = {
target_host = {type = "string"},
},
}
local _M = {
version = 0.1,
priority = 1000,
name = plugin_name,
schema = schema,
}
function _M.access(conf, ctx)
if ngx.var.scheme == "http" then
local host = conf.target_host or ngx.var.host
local target = "https://" .. host .. ngx.var.request_uri
return ngx.redirect(target, ngx.HTTP_MOVED_PERMANENTLY)
end
end
return _M