diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 51a9fec1d..822c68e93 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -171,7 +171,6 @@ var ( "proxySetHeader": proxySetHeader, "buildInfluxDB": buildInfluxDB, "enforceRegexModifier": enforceRegexModifier, - "stripLocationModifer": stripLocationModifer, "buildCustomErrorDeps": buildCustomErrorDeps, "buildCustomErrorLocationsPerServer": buildCustomErrorLocationsPerServer, "shouldLoadModSecurityModule": shouldLoadModSecurityModule, @@ -373,10 +372,6 @@ func needsRewrite(location *ingress.Location) bool { return false } -func stripLocationModifer(path string) string { - return strings.TrimLeft(path, "~* ") -} - // enforceRegexModifier checks if the "rewrite-target" or "use-regex" annotation // is used on any location path within a server func enforceRegexModifier(input interface{}) bool { diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index 7a8599f67..2f2dd670a 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -1221,15 +1221,6 @@ func TestEnforceRegexModifier(t *testing.T) { } } -func TestStripLocationModifer(t *testing.T) { - expected := "ok.com" - actual := stripLocationModifer("~*ok.com") - - if expected != actual { - t.Errorf("Expected '%v' but returned '%v'", expected, actual) - } -} - func TestShouldLoadModSecurityModule(t *testing.T) { // ### Invalid argument type tests ### // The first tests should return false. diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index e638672a3..cef735766 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1136,12 +1136,6 @@ stream { {{ buildInfluxDB $location.InfluxDB }} - {{ if not (empty $location.Redirect.URL) }} - if ($uri ~* {{ stripLocationModifer $path }}) { - return {{ $location.Redirect.Code }} {{ $location.Redirect.URL }}; - } - {{ end }} - {{ if isValidByteSize $location.Proxy.BodySize true }} client_max_body_size {{ $location.Proxy.BodySize }}; {{ end }} @@ -1267,6 +1261,10 @@ stream { fastcgi_param {{ $k }} {{ $v | quote }}; {{ end }} + {{ if not (empty $location.Redirect.URL) }} + return {{ $location.Redirect.Code }} {{ $location.Redirect.URL }}; + {{ end }} + {{ buildProxyPass $server.Hostname $all.Backends $location }} {{ if (or (eq $location.Proxy.ProxyRedirectFrom "default") (eq $location.Proxy.ProxyRedirectFrom "off")) }} proxy_redirect {{ $location.Proxy.ProxyRedirectFrom }}; diff --git a/test/e2e/annotations/redirect.go b/test/e2e/annotations/redirect.go index b18b8f276..cb6285562 100644 --- a/test/e2e/annotations/redirect.go +++ b/test/e2e/annotations/redirect.go @@ -46,8 +46,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code", f.WaitForNginxServer(host, func(server string) bool { - return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) && - strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL)) + return strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL)) }) ginkgo.By("sending request to redirected URL path") @@ -77,8 +76,7 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code", f.WaitForNginxServer(host, func(server string) bool { - return strings.Contains(server, fmt.Sprintf("if ($uri ~* %s) {", redirectPath)) && - strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL)) + return strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL)) }) ginkgo.By("sending request to redirected URL path")