diff --git a/roles/vhost/defaults/main.yaml b/roles/vhost/defaults/main.yaml index 14b0ea7..a014583 100644 --- a/roles/vhost/defaults/main.yaml +++ b/roles/vhost/defaults/main.yaml @@ -19,5 +19,6 @@ vhost_proxy_delete_headers: [] vhost_redirect_type: temporary vhost_redirect_preserve_path: false +vhost_redirect_preserve_query: "{{ vhost_redirect_preserve_path }}" vhost_respond_content_type: plain diff --git a/roles/vhost/meta/argument_specs.yaml b/roles/vhost/meta/argument_specs.yaml index a060c44..533a5b6 100644 --- a/roles/vhost/meta/argument_specs.yaml +++ b/roles/vhost/meta/argument_specs.yaml @@ -117,8 +117,13 @@ argument_specs: type: bool required: false default: false - redirect type: - description: Only applicable if vhost_type is reverse_proxy + vhost_redirect_preserve_query: + description: Whether to keep the original request query string + type: bool + required: false + default: "{{ vhost_redirect_preserve_path }}" + redirect_type: + description: Only applicable if vhost_type is redirect type: str required: false default: temporary @@ -234,8 +239,13 @@ argument_specs: type: bool required: false default: "{{ vhost_redirect_preserve_path }}" + redirect_preserve_query: + description: Whether to keep the original request query string + type: bool + required: false + default: "{{ vhost_redirect_preserve_query }}" redirect_type: - description: Only applicable if vhost_type is reverse_proxy + description: Only applicable if vhost_type is redirect type: str required: false default: "{{ vhost_redirect_type }}" diff --git a/roles/vhost/tasks/caddy.yaml b/roles/vhost/tasks/caddy.yaml index 01ce24c..9f756d5 100644 --- a/roles/vhost/tasks/caddy.yaml +++ b/roles/vhost/tasks/caddy.yaml @@ -41,7 +41,7 @@ request_header -{{ header }} {% endfor %} {% elif location.type == 'redirect' %} - redir {{ location.redirect_target }}{{ '{uri}' if location.redirect_preserve_path }} {{ location.redirect_type }} + redir * {{ location.redirect_target }}{{ '{path}' if location.redirect_preserve_path }}{{ '?{query}' if location.redirect_preserve_query }} {{ location.redirect_type }} {% elif location.type == 'respond' %} {% if location.respond_content_type == 'json' %} respond `{{ location.respond_content | to_json }}` diff --git a/roles/vhost/tasks/main.yaml b/roles/vhost/tasks/main.yaml index fe4c3ad..d9b9262 100644 --- a/roles/vhost/tasks/main.yaml +++ b/roles/vhost/tasks/main.yaml @@ -41,6 +41,7 @@ 'redirect_target': item.redirect_target | default(vhost_redirect_target if vhost_type == 'redirect' else ''), 'redirect_preserve_path': item.redirect_preserve_path | default(vhost_redirect_preserve_path), + 'redirect_preserve_query': item.redirect_preserve_query | default(vhost_redirect_preserve_query), 'redirect_type': item.redirect_type | default(vhost_redirect_type), 'respond_content': item.respond_content | default(vhost_respond_content if vhost_type == 'respond' else ''),