@@ -104,19 +104,33 @@ func authenticate(store *datastore.Datastore, fn http.HandlerFunc, authMethod st
104
104
return func (w http.ResponseWriter , req * http.Request ) {
105
105
// canonical host
106
106
if store .Settings .CanonicalURL != "" && store .Settings .ServerIsLVE { // set in ENV
107
- root := strings .ToLower (req .URL .Host + req .URL .Path )
107
+ canonical := store .Settings .CanonicalURL
108
+ root := strings .ToLower (req .Host )
108
109
if ! strings .HasSuffix (root , "/" ) {
109
110
root += "/"
110
111
}
111
- if store .Settings .CanonicalURL != root {
112
- redirectURL := store .Settings .CanonicalURL
112
+ if ! strings .HasSuffix (canonical , "/" ) {
113
+ canonical += "/"
114
+ }
115
+ // logrus.Info("root", root)
116
+ // logrus.Info("root", canonical)
117
+ if canonical != root {
118
+ redirectURL := "http://"
119
+ if store .Settings .IsSecured {
120
+ redirectURL = "https://"
121
+ }
122
+ redirectURL += strings .TrimRight (canonical , "/" )
123
+ if req .URL .Path != "" {
124
+ redirectURL += req .URL .Path
125
+ // logrus.Info("0", redirectURL)
126
+ }
113
127
if req .URL .RawQuery != "" {
114
- logrus .Info ("1" , redirectURL )
115
128
redirectURL += "?" + req .URL .RawQuery
129
+ // logrus.Info("2", redirectURL)
116
130
}
117
131
if req .URL .Fragment != "" {
118
- logrus .Info ("2" , redirectURL )
119
132
redirectURL += "#" + req .URL .Fragment
133
+ // logrus.Info("2", redirectURL)
120
134
}
121
135
122
136
logrus .Info ("3" , redirectURL )
0 commit comments