aboutsummaryrefslogtreecommitdiff
path: root/handle.go
diff options
context:
space:
mode:
authorthinkpadmaster <a.scerba02@gmail.com>2023-07-21 21:54:23 -0500
committerAlex Scerba <alex@scerba.org>2024-10-29 13:19:57 -0400
commitfa4169e37b6d913cb3fd3e79ae1f00459399eccb (patch)
tree6112de31f14433078ec41162faa2f6fda45e00f7 /handle.go
parent71c13f58320cb52786e72ee240de69a1ffd70b07 (diff)
Redirect URLs ending it / to the URL without a trailing /
Diffstat (limited to 'handle.go')
-rw-r--r--handle.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/handle.go b/handle.go
index 20fa259..5059c1d 100644
--- a/handle.go
+++ b/handle.go
@@ -26,6 +26,10 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) {
}
func (app *application) about(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == "/about/" {
+ http.Redirect(w, r, "/about", http.StatusFound)
+ return
+ }
err := renderTemplate(w, "main/about", nil)
if err != nil {
app.serverError(w, err)
@@ -44,8 +48,11 @@ func (app *application) aggregate(w http.ResponseWriter, r *http.Request) {
func (app *application) post(w http.ResponseWriter, r *http.Request) {
path := strings.Split(r.URL.Path, "/")
- if path[2] == "" {
+ if r.URL.Path == "/blog" || r.URL.Path == "/projects" {
app.aggregate(w, r)
+ } else if path[2] == "" {
+ http.Redirect(w, r, strings.TrimSuffix(r.URL.Path, "/"), http.StatusFound)
+ return
} else {
post, err := app.readFile("html" + strings.TrimSuffix(r.URL.Path, "/") + ".tmpl.html")
if err != nil {