diff --git a/pkg/nginx/template/template.go b/pkg/nginx/template/template.go
index 5469000a7..794099a6a 100644
--- a/pkg/nginx/template/template.go
+++ b/pkg/nginx/template/template.go
@@ -323,14 +323,13 @@ func buildProxyPass(host string, b interface{}, loc interface{}) string {
if location.Rewrite.AddBaseURL {
// path has a slash suffix, so that it can be connected with baseuri directly
bPath := fmt.Sprintf("%s%s", path, "$baseuri")
+ regex := `(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)`
if len(location.Rewrite.BaseURLScheme) > 0 {
- abu = fmt.Sprintf(`subs_filter '
' '' r;
- subs_filter '' '' r;
- `, location.Rewrite.BaseURLScheme, bPath, location.Rewrite.BaseURLScheme, bPath)
+ abu = fmt.Sprintf(`subs_filter '%v' '$1' ro;
+ `, regex, location.Rewrite.BaseURLScheme, bPath)
} else {
- abu = fmt.Sprintf(`subs_filter '' '' r;
- subs_filter '' '' r;
- `, bPath, bPath)
+ abu = fmt.Sprintf(`subs_filter '%v' '$1' ro;
+ `, regex, bPath)
}
}
diff --git a/pkg/nginx/template/template_test.go b/pkg/nginx/template/template_test.go
index cecc69b9a..2fc192573 100644
--- a/pkg/nginx/template/template_test.go
+++ b/pkg/nginx/template/template_test.go
@@ -64,34 +64,29 @@ var (
"redirect / to /jenkins and rewrite": {"/", "/jenkins", "~* /", `
rewrite /(.*) /jenkins/$1 break;
proxy_pass http://upstream-name;
- subs_filter '' '' r;
- subs_filter '' '' r;
+ subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1' ro;
`, true, ""},
"redirect /something to / and rewrite": {"/something", "/", `~* ^/something\/?(?.*)`, `
rewrite /something/(.*) /$1 break;
rewrite /something / break;
proxy_pass http://upstream-name;
- subs_filter '' '' r;
- subs_filter '' '' r;
+ subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1' ro;
`, true, ""},
"redirect /end-with-slash/ to /not-root and rewrite": {"/end-with-slash/", "/not-root", `~* ^/end-with-slash/(?.*)`, `
rewrite /end-with-slash/(.*) /not-root/$1 break;
proxy_pass http://upstream-name;
- subs_filter '' '' r;
- subs_filter '' '' r;
+ subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1' ro;
`, true, ""},
"redirect /something-complex to /not-root and rewrite": {"/something-complex", "/not-root", `~* ^/something-complex\/?(?.*)`, `
rewrite /something-complex/(.*) /not-root/$1 break;
proxy_pass http://upstream-name;
- subs_filter '' '' r;
- subs_filter '' '' r;
+ subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1' ro;
`, true, ""},
"redirect /something to / and rewrite with specific scheme": {"/something", "/", `~* ^/something\/?(?.*)`, `
rewrite /something/(.*) /$1 break;
rewrite /something / break;
proxy_pass http://upstream-name;
- subs_filter '' '' r;
- subs_filter '' '' r;
+ subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1' ro;
`, true, "http"},
}
)