Skip to content

Commit d2859d8

Browse files
authored
Merge pull request #19 from mikemrm/regex-support
add regex matching support
2 parents b4af249 + bd5b62e commit d2859d8

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
map $http_host $redir_to {
1+
map $host$request_uri $redir_to {
22
default "not-found";
3-
{{- range $shost, $dhost := .Values.redirects }}
4-
{{ $shost }} {{ quote $dhost }};
3+
{{- range $src, $dst := .Values.redirects }}
4+
{{- if hasPrefix "^" $src }}
5+
{{ printf "~%s" $src }} {{ quote $dst }};
6+
{{- end }}
7+
{{- end }}
8+
}
9+
10+
map $host $redir_host_to {
11+
default "not-found";
12+
{{- range $src, $dst := .Values.redirects }}
13+
{{- if not (hasPrefix "^" $src) }}
14+
{{ quote $src }} {{ quote $dst }};
15+
{{- end }}
516
{{- end }}
617
}
718

@@ -10,12 +21,14 @@ server {
1021
server_name localhost default_server;
1122

1223
location / {
13-
if ($redir_to = "not-found") {
14-
add_header Content/Type text/plain;
24+
if ($redir_to != "not-found") {
25+
return 301 $redir_to;
26+
}
1527

16-
return 404;
28+
if ($redir_host_to != "not-found") {
29+
return 301 $redir_host_to;
1730
}
1831

19-
return 301 $redir_to;
32+
return 404;
2033
}
2134
}

nginx-redirect/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
redirects: {}
22
# redirect.host: https://redirect/url
3+
# ^redirect.host/path$: https://redirect/url
34

45
nameOverride: ""
56
fullnameOverride: ""
@@ -24,4 +25,4 @@ ingress:
2425

2526
annotations: {}
2627
hosts: []
27-
tls: {}
28+
tls: []

0 commit comments

Comments
 (0)