map $args $_args {
~^redirect=[^&]*&?(.*) $1;
~^(.*?)&redirect=[^&]*(&?.*) $1$2;
}
server {
location = / {
error_page 418 = @rewrite;
if ($arg_redirect ~ '^(?<_url>https?://[\w.-]+)') {
return 418;
}
}
location @rewrite {
rewrite ^ /?$_args? break;
proxy_pass $_url;
proxy_http_version 1.1;
proxy_ssl_server_name on;
resolver 8.8.8.8;
}