[object Object]

← back to Stringwallpaper

clean-url: 301 legacy /foo.html to /foo before static, index.html exempt

53a94322443f450217d31b258575c77da2d5b45f · 2026-06-01 07:51:00 -0700 · Steve Abrams

Files touched

Diff

commit 53a94322443f450217d31b258575c77da2d5b45f
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Jun 1 07:51:00 2026 -0700

    clean-url: 301 legacy /foo.html to /foo before static, index.html exempt
---
 server.js | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/server.js b/server.js
index 873b541..4d98615 100644
--- a/server.js
+++ b/server.js
@@ -157,6 +157,15 @@ app.use((req, res, next) => {
   if (/\.bak([.-]|$)|\.pre-[^/]*/i.test(req.path)) return res.status(404).send('Not found');
   next();
 });
+// Clean-URL canonicalization: 301 the legacy /foo.html form to /foo so the
+// extension-less route is the single source of truth (no duplicate content).
+// Runs BEFORE express.static so the .html never serves directly; index.html
+// is left alone so "/" keeps working.
+app.get(/^\/([a-z0-9-]+)\.html$/i, (req, res, next) => {
+  const name = req.params[0];
+  if (name === 'index') return next();
+  res.redirect(301, `/${name}`);
+});
 app.use(express.static(path.join(__dirname, 'public')));
 
 // Clean-URL routes for extension-less nav links → their static .html pages.

← f3a5999 fix: remove leaked bak file from public/, expand .gitignore  ·  back to Stringwallpaper  ·  Remove Big Red widget — never UX-worked, collided with Help e82142f →