summaryrefslogtreecommitdiff
path: root/srv/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'srv/src/http')
-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
}