express-htaccess-middleware
An express middleware that interprets .htaccess rewrite rules.
Installation
npm i express-htaccess-middleware
Usage
var path = ;var express = ;var RewriteMiddleware = ;var RewriteOptions = file: path verbose: processenvENV_NODE == 'development' watch: processenvENV_NODE == 'development'; var app = ;app;app;
If the verbose option is set to true, the rules not understood by this module will be shown in the console. The redirections will also be displayed.
This is very useful to debug your redirections when developing your app.
If the watch option is set to true, the rewrite rules will be automatically reloaded whenever the htaccess file is modified.
Supported directives
RewriteEngine on|off
The RewriteEngine on
directive enables the rewriting engine.
RewriteBase URL-path
Sets the base URL for rewrites.
RewriteCond TestVariable Pattern [Flags]
Defines a condition under which rewriting will take place. The pattern has to be a regular expression.
Supported variables
-
%{REQUEST_METHOD}
-
%{REQUEST_URI}
-
%{THE_REQUEST}
-
%{HTTP_HOST}
-
%{HTTP_USER_AGENT}
-
%{HTTP_REFERER}
-
%{QUERY_STRING}
-
%{ENV:...}
Supported flags
-
NC
-
OR
RewriteRule Pattern Substitution [Flags]
Defines rules for the rewriting engine
Supported flags
-
NC
-
R
-
N
-
L
-
F
-
G
-
QSA
-
QSD
-
S=x