Merge pull request #296 from aledbf/fix-rewrite

Fix rewrite regex to match the start of the URL and not a substring
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-02-17 15:12:18 -03:00 committed by GitHub
commit f8f4c24ff8
2 changed files with 8 additions and 5 deletions

View file

@ -237,7 +237,10 @@ func buildLocation(input interface{}) string {
path := location.Path
if len(location.Redirect.Target) > 0 && location.Redirect.Target != path {
return fmt.Sprintf("~* %s", path)
if path == "/" {
return fmt.Sprintf("~* %s", path)
}
return fmt.Sprintf("~* ^%s", path)
}
return path

View file

@ -45,12 +45,12 @@ var (
rewrite /(.*) /jenkins/$1 break;
proxy_pass http://upstream-name;
`, false},
"redirect /something to /": {"/something", "/", "~* /something", `
"redirect /something to /": {"/something", "/", "~* ^/something", `
rewrite /something/(.*) /$1 break;
rewrite /something / break;
proxy_pass http://upstream-name;
`, false},
"redirect /something-complex to /not-root": {"/something-complex", "/not-root", "~* /something-complex", `
"redirect /something-complex to /not-root": {"/something-complex", "/not-root", "~* ^/something-complex", `
rewrite /something-complex/(.*) /not-root/$1 break;
proxy_pass http://upstream-name;
`, false},
@ -60,14 +60,14 @@ var (
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name/jenkins/">' r;
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name/jenkins/">' r;
`, true},
"redirect /something to / and rewrite": {"/something", "/", "~* /something", `
"redirect /something to / and rewrite": {"/something", "/", "~* ^/something", `
rewrite /something/(.*) /$1 break;
rewrite /something / break;
proxy_pass http://upstream-name;
subs_filter '<head(.*)>' '<head$1><base href="$scheme://$server_name/">' r;
subs_filter '<HEAD(.*)>' '<HEAD$1><base href="$scheme://$server_name/">' r;
`, true},
"redirect /something-complex to /not-root and rewrite": {"/something-complex", "/not-root", "~* /something-complex", `
"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 '<head(.*)>' '<head$1><base href="$scheme://$server_name/not-root/">' r;