For URLs without trailing slashes which resolve do a directory, do a redirect to add the trailing slash.
This commit is contained in:
parent
aad4ebba8f
commit
756f9df7e4
|
@ -57,8 +57,15 @@ func GetHandler(config Config) http.HandlerFunc {
|
||||||
http.Error(w, "Permission denied.", http.StatusForbidden)
|
http.Error(w, "Permission denied.", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Add index.html to directory paths, if it exists
|
// Handle URLS which map to a directory
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
|
// Redirect to add trailing slash if missing
|
||||||
|
// (otherwise relative links don't work properly)
|
||||||
|
if !strings.HasSuffix(r.URL.Path, "/") {
|
||||||
|
http.Redirect(w, r, r.URL.String()+"/", http.StatusMovedPermanently)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Add index.html to directory paths, if it exists
|
||||||
index_path := filepath.Join(path, "index.html")
|
index_path := filepath.Join(path, "index.html")
|
||||||
index_info, err := os.Stat(index_path)
|
index_info, err := os.Stat(index_path)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in New Issue