Skip to content

Commit

Permalink
feat: handle clean urls e.g. /foo.html -> /foo/
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydw committed Jan 6, 2024
1 parent 3d08252 commit d236f4d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ export function createApp(siteId: string) {
blobKey = manifest.paths[`${urlPath}/index.html`];
}

// If a blob wasn't found, and if the URL ends with ".html", and if a
// corresponding blob exists at a clean URL, redirect automatically.
// For example, this will redirect `/foo/bar.html` to `/foo/bar/` if
// `/foo/bar/index.html` exists in the manifest.
const cleanPath = urlPath.replace(/\.html$/, '');
if (
!blobKey &&
urlPath.endsWith('.html') &&
manifestPaths[`${cleanPath}/index.html`]
) {
res.redirect(301, preserveQueryString(req, `${cleanPath}/`));
return;
}

if (!blobKey) {
// Trailing slash redirect.
if (
Expand Down

0 comments on commit d236f4d

Please sign in to comment.