[object Object]

← back to 1920swallpaper

add 301 redirect from legacy .html URLs to clean-URL form

bcb7468877779217197aa4b3b380d7286b6ad464 · 2026-06-01 07:11:01 -0700 · SteveStudio2

Files touched

Diff

commit bcb7468877779217197aa4b3b380d7286b6ad464
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Mon Jun 1 07:11:01 2026 -0700

    add 301 redirect from legacy .html URLs to clean-URL form
---
 server.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/server.js b/server.js
index cec26ce..3560a2a 100644
--- a/server.js
+++ b/server.js
@@ -154,6 +154,16 @@ app.use((req, res, next) => {
   next();
 });
 
+// Clean-URL canonicalization: 301 the legacy `/foo.html` form to `/foo`.
+// Static serving below resolves the clean form via `extensions: ['html']`.
+// Skips index.html (root) and anything starting with /api.
+app.get(/^\/(?!api\/).+\.html$/i, (req, res, next) => {
+  const clean = req.path.replace(/\/index\.html$/i, '/').replace(/\.html$/i, '');
+  if (clean === req.path) return next();
+  const qs = req.originalUrl.slice(req.path.length); // preserve ?query
+  return res.redirect(301, (clean || '/') + qs);
+});
+
 app.use(express.static(path.join(__dirname, 'public'), { extensions: ['html'] }));
 
 // Shared query-filter — applied identically by /api/products AND /api/facets so

← ca80344 fix /api/facets to count the filtered result set, not the wh  ·  back to 1920swallpaper  ·  Remove Big Red widget — never UX-worked, collided with Help 6247611 →