29 lines
574 B
Lua
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
|