Replace request_uri
This commit is contained in:
parent
108637bb1c
commit
493dd6726d
6 changed files with 31 additions and 16 deletions
|
|
@ -145,11 +145,17 @@ function _M.rewrite(location_config)
|
|||
end
|
||||
|
||||
if redirect_to_https(location_config) then
|
||||
local uri = string_format("https://%s%s", redirect_host(), ngx.var.request_uri)
|
||||
local request_uri = ngx.var.request_uri
|
||||
-- do not append a trailing slash on redirects
|
||||
if string.sub(request_uri, -1) == "/" then
|
||||
request_uri = string.sub(request_uri, 1, -2)
|
||||
end
|
||||
|
||||
local uri = string_format("https://%s%s", redirect_host(), request_uri)
|
||||
|
||||
if location_config.use_port_in_redirects then
|
||||
uri = string_format("https://%s:%s%s", redirect_host(),
|
||||
config.listen_ports.https, ngx.var.request_uri)
|
||||
config.listen_ports.https, request_uri)
|
||||
end
|
||||
|
||||
ngx_redirect(uri, config.http_redirect_code)
|
||||
|
|
|
|||
|
|
@ -554,12 +554,21 @@ http {
|
|||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if ne $all.ListenPorts.HTTPS 443 }}
|
||||
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
|
||||
return {{ $all.Cfg.HTTPRedirectCode }} $scheme://{{ $redirect.To }}{{ $redirect_port }}$request_uri;
|
||||
{{ else }}
|
||||
return {{ $all.Cfg.HTTPRedirectCode }} $scheme://{{ $redirect.To }}$request_uri;
|
||||
{{ end }}
|
||||
set_by_lua_block $redirect_to {
|
||||
local request_uri = ngx.var.request_uri
|
||||
if string.sub(request_uri, -1) == "/" then
|
||||
request_uri = string.sub(request_uri, 1, -2)
|
||||
end
|
||||
|
||||
{{ if ne $all.ListenPorts.HTTPS 443 }}
|
||||
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
|
||||
return string.format("%s://%s%s%s", ngx.var.scheme, "{{ $redirect.To }}", "{{ $redirect_port }}", request_uri)
|
||||
{{ else }}
|
||||
return string.format("%s://%s%s", ngx.var.scheme, "{{ $redirect.To }}", request_uri)
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
return {{ $all.Cfg.HTTPRedirectCode }} $redirect_to;
|
||||
}
|
||||
## end server {{ $redirect.From }}
|
||||
{{ end }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue