From 089dc4fbfb863eb1d289038a91b756efef53096b Mon Sep 17 00:00:00 2001 From: AnsibleGuy Date: Thu, 13 Jan 2022 18:38:47 +0100 Subject: [PATCH] updated plain-site redirect to preserve the request host(name) --- defaults/main.yml | 1 + templates/etc/apache2/sites-available/site.conf.j2 | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 5f1f8cc..9ba4ae6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -108,6 +108,7 @@ default_site_config: ip: http_versions: [2, 1] plain_site: true # if http site (only used for redirect to https) should be created + plain_redirect: 'preserve_domain' # keep hostname from plain request => any other value will set the redirect to the main-domain config: {} # site-specific setting-value pairs config_additions: [] # lines that will 1-to-1 be appended to the site-config diff --git a/templates/etc/apache2/sites-available/site.conf.j2 b/templates/etc/apache2/sites-available/site.conf.j2 index 0c1dd7b..94bb3dc 100644 --- a/templates/etc/apache2/sites-available/site.conf.j2 +++ b/templates/etc/apache2/sites-available/site.conf.j2 @@ -30,7 +30,12 @@ Protocols {% if 2 in site.http_versions %}h2c {% endif %}{% if 1 in site.http_versions or 2 not in site.http_versions %}http/1.1{% endif %} # redirect all to secure connection - Redirect permanent / https://{{ site.domain }} + RewriteEngine On +{% if site.plain_redirect == 'preserve_domain' %} + RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} +{% else %} + RewriteRule ^ https://{{ site.domain }}%{REQUEST_URI} +{% endif %} {% endif %}