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 %}