Skip to content

Commit

Permalink
Add support for PermanentRedirects through configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jun 15, 2024
1 parent e986b11 commit cf62470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Configuration struct {
CMSHeaders bool `json:"cms_headers"` // set CMS headers
RedirectURL string `json:"redirect_url"` // redirect auth url for proxy server
Verbose int `json:"verbose"` // verbose output
PermanentRedirects []string `json:"permanent_redirects"` // list of permanent redirects
Ingress []Ingress `json:"ingress"` // incress section
ServerCrt string `json:"server_cert"` // server certificate
ServerKey string `json:"server_key"` // server certificate
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,17 @@ func srvURL(surl string) string {

// helper function to redirect HTTP requests based on configuration ingress rules
func redirect(w http.ResponseWriter, r *http.Request) {
// check for permanent redirects first
if !InList(r.URL.Path, Config.PermanentRedirects) {
path := fmt.Sprintf("%s/index.html", r.URL.Path)
path = strings.Replace(path, "//", "/", -1)
http.Redirect(w, r, path, http.StatusMovedPermanently)
return
}
// get redirect rule map and rules (in reverse order)
// here the reverse order will provide /path/rse /path/aaa followed by /path, etc.
// such that we can match the /path as last reserve
rmap, rules := RedirectRules(Config.Ingress)
// special CMS cases
if r.URL.Path == "/wmstats" {
r.URL.Path = "/wmstats/index.html"
} else if r.URL.Path == "/tier0_wmstats" {
r.URL.Path = "/tier0_wmstats/index.html"
}
for _, key := range rules {
rec := rmap[key]
// check that request URL path had ingress path with slash
Expand Down

0 comments on commit cf62470

Please sign in to comment.