Skip to content

Conversation

@kenzycodex
Copy link

Clean URLs Middleware Enhancement

This PR adds a new middleware that provides clean URL routing for HTML files while maintaining proper HTTP headers and query parameter handling.

Features

  • Removes .html extensions from URLs (e.g., /about.html/about)
  • Preserves query parameters during redirects
  • Sets proper UTF-8 charset in Content-Type headers
  • Handles trailing slashes consistently
  • Maintains backward compatibility with direct .html requests
  • Properly handles URL-encoded characters

Implementation Details

  • Added middleware/clean-urls.js with comprehensive URL handling
  • Includes full test coverage in test/clean-urls.test.js
  • Adds Cache-Control headers for redirects
  • Handles edge cases (root path, missing files)

Testing

All tests pass and cover:

  • Non-HTML file handling
  • Query parameter preservation
  • URL encoding preservation
  • Trailing slash handling
  • Root path resolution
  • Direct .html requests

Breaking Changes

None. This is an opt-in middleware that maintains compatibility with existing behavior.

@akriegman
Copy link

akriegman commented Oct 22, 2025

Hey, I was looking for this feature, I would love it if this could get merged. Personally would also prefer if this was enabled by default.

@akriegman
Copy link

But also there's a bug. If you navigate to /folder or /folder/, you get redirected to /folder//.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants