summaryrefslogtreecommitdiff
path: root/srv
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-21 10:50:42 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-21 10:50:42 -0600
commite92f59fc7ff48a65582fc03e192ac0b8d27aebec (patch)
tree6bca994abdfc3efc910277affdfaf1979736a539 /srv
parent0361b1d4bf69cf35f33ab0672c72957d0d5499da (diff)
Redirect legacy URL path
Diffstat (limited to 'srv')
-rw-r--r--srv/src/http/index.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/srv/src/http/index.go b/srv/src/http/index.go
index aa606d6..a392361 100644
--- a/srv/src/http/index.go
+++ b/srv/src/http/index.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"path/filepath"
+ "regexp"
"strings"
"github.com/mediocregopher/blog.mediocregopher.com/srv/http/apiutil"
@@ -12,12 +13,24 @@ import (
func (a *api) renderIndexHandler() http.Handler {
+ legacyPostPathRegexp := regexp.MustCompile(
+ `^/[0-9]{4}/[0-9]{2}/[0-9]{2}/([^/.]+)\.html$`,
+ )
+
tpl := a.mustParseBasedTpl("index.html")
const pageCount = 10
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
- if path := r.URL.Path; !strings.HasSuffix(path, "/") && filepath.Base(path) != "index.html" {
+ path := r.URL.Path
+
+ if matches := legacyPostPathRegexp.FindStringSubmatch(path); len(matches) == 2 {
+ id := matches[1]
+ http.Redirect(rw, r, filepath.Join("/posts", id), http.StatusMovedPermanently)
+ return
+ }
+
+ if !strings.HasSuffix(path, "/") && filepath.Base(path) != "index.html" {
http.Error(rw, "Page not found", 404)
return
}