Skip to content

Commit 1e51e71

Browse files
committed
Updates
1 parent ef6097f commit 1e51e71

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

services/traefik/docker-compose.yml.j2

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,27 @@ services:
152152
###
153153
{% set redirect_from_domains_list = TRAEFIK_DOMAINS_REDIRECT_FROM.split(',') %}
154154
{% set redirect_to_domains_list = TRAEFIK_DOMAINS_REDIRECT_TO.split(',') %}
155+
{% set redirect_is_permanent_list = TRAEFIK_DOMAINS_REDIRECT_IS_PERMANENT.split(',') %}
155156
156-
{% for from_domain, to_domain in zip(redirect_from_domains_list, redirect_to_domains_list) %}
157+
{% for ix in range(redirect_from_domains_list | length) %}
158+
159+
{% set from_domain = redirect_from_domains_list[ix] %}
157160
{% set from_domain_no_dots = from_domain.replace(".", "-") %}
161+
{% set to_domain = redirect_to_domains_list[ix] %}
162+
{% set redirect_is_permanent = redirect_is_permanent_list[ix] %}
163+
158164
# Regex below is redirecting any subdomains and path to new domain.
159165
# Use https://regex101.com/r/58sIgx/2 for regex explanation and experimentation.
160166
# Below we include dollar escaping and j2 expressions. It is not clean / pure regex
161167
# You can fetch baked and clean regex from traefik dashboards.
162168
- traefik.http.middlewares.redirect-{{ from_domain_no_dots }}.redirectregex.regex=^https?://((?:[a-zA-Z0-9-]+\.)*)*{{ from_domain }}(.*)$$
163169
- traefik.http.middlewares.redirect-{{ from_domain_no_dots }}.redirectregex.replacement=https://$${1}{{ to_domain }}$${2}
164-
- traefik.http.middlewares.redirect-{{ from_domain_no_dots }}.redirectregex.permanent=false
170+
- traefik.http.middlewares.redirect-{{ from_domain_no_dots }}.redirectregex.permanent={{ redirect_is_permanent }}
165171
- traefik.http.routers.{{ from_domain_no_dots }}.rule={{ generate_domain_capture_all_rule(from_domain) }}
166172
- traefik.http.routers.{{ from_domain_no_dots }}.middlewares=redirect-{{ from_domain_no_dots }}
167173
- traefik.http.routers.{{ from_domain_no_dots }}.entrypoints=https
168174
- traefik.http.routers.{{ from_domain_no_dots }}.tls=true
175+
169176
{% endfor %}
170177
171178
networks:

services/traefik/j2cli_customization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def _generate_domain_capture_all_rule(domain: str) -> str:
1717

1818
def j2_environment(env):
1919
env.globals.update(
20-
generate_domain_capture_all_rule=_generate_domain_capture_all_rule,
21-
zip=zip,
20+
generate_domain_capture_all_rule=_generate_domain_capture_all_rule
2221
)
2322
return env

services/traefik/template.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ WEBSERVER_PORT=${WEBSERVER_PORT}
4040

4141
TRAEFIK_DOMAINS_REDIRECT_FROM=${TRAEFIK_DOMAINS_REDIRECT_FROM}
4242
TRAEFIK_DOMAINS_REDIRECT_TO=${TRAEFIK_DOMAINS_REDIRECT_TO}
43+
TRAEFIK_DOMAINS_REDIRECT_IS_PERMANENT=${TRAEFIK_DOMAINS_REDIRECT_IS_PERMANENT}

0 commit comments

Comments
 (0)