This package, `http-rewrite-middleware`, provides Nginx-inspired, regular expression-based URL rewriting functionality as a middleware for Connect and Express web servers. It allows developers to define rules for internal rewrites (where the server processes the new URL internally without notifying the client) or external HTTP 301 (permanent) or 302 (temporary) redirects (where the client is instructed to request a new URL). The current version available is 0.1.6, though the provided README refers to v0.1.5. Its `node >= 0.8.0` engine requirement and low version number indicate that the package has likely not seen significant active development in many years, suggesting it is either abandoned or in a very minimal maintenance state. Its primary differentiators are its straightforward, rule-based approach for managing both internal URL transformations and client-side redirects, similar to how Nginx's `rewrite` module operates, making it a direct successor to `grunt-connect-rewrite` for Grunt-based setups.
npm install http-rewrite-middlewareVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `http-rewrite-middleware` with Express, configuring both internal URL rewrites and HTTP 301/302 redirects with verbose logging for debugging.
Ensure `app.use(rewriteMiddleware)` is called early in your Connect/Express middleware stack, generally before `express.static()` or main router definitions.
Always explicitly define the `redirect` option if you intend for the client's browser to update its URL or perform a visible redirect; otherwise, the change is internal to the server.
Thoroughly test your rewrite rules with various URL patterns. Use tools like regex101.com to validate your regular expressions. Enable verbose logging (`getMiddleware(rules, { verbose: true })`) for detailed insights into matched rules.Verify that `http-rewrite-middleware` is listed in your `package.json` and installed (`npm install`). Ensure `const rewriteModule = require('http-rewrite-middleware');` is correctly placed and spelled.Ensure that after a rewrite, the target URL (`__to__`) corresponds to an existing static file, a defined route, or another middleware capable of handling the request. For debugging, enable `verbose: true` to confirm which rules are matching.
No dependency data recorded yet.