# @aredridel/express-htaccess-middleware

> An express middleware that interprets .htaccess rewrite rules.

Latest version **1.0.1** (published 2017-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @aredridel/express-htaccess-middleware
pnpm add @aredridel/express-htaccess-middleware
yarn add @aredridel/express-htaccess-middleware
bun add @aredridel/express-htaccess-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-08-06 |
| First published | 2017-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.0.0 |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Mickael Burguet |
| Maintainers | aredridel |
| Keywords | htaccess, rewrite, mod_rewrite, redirect, redirection, express |

## Links

- npm: https://www.npmjs.com/package/@aredridel/express-htaccess-middleware
- Repository: https://github.com/rundef/node-express-htaccess-middleware
- Homepage: https://github.com/rundef/node-express-htaccess-middleware#readme
- Issues: https://github.com/rundef/node-express-htaccess-middleware/issues
- npm.io page: https://npm.io/package/@aredridel/express-htaccess-middleware

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [app-root-path](https://npm.io/package/app-root-path.md) ^1.2.1
- [htaccess-parser](https://npm.io/package/htaccess-parser.md) 0.1.0

## Recent versions

- 1.0.1 (latest) — 2017-08-06
- 1.0.0 — 2017-08-06

## README

# express-htaccess-middleware

[![npm version](https://badge.fury.io/js/express-htaccess-middleware.svg)](http://badge.fury.io/js/express-htaccess-middleware) 
[![Travis](https://travis-ci.org/rundef/node-express-htaccess-middleware.svg?branch=master)](https://travis-ci.org/rundef/node-express-htaccess-middleware?branch=master) 
[![Coverage Status](https://coveralls.io/repos/github/rundef/node-express-htaccess-middleware/badge.svg?branch=master)](https://coveralls.io/github/rundef/node-express-htaccess-middleware?branch=master)

An express middleware that interprets **.htaccess** rewrite rules.

## Installation

> npm i express-htaccess-middleware

## Usage

```javascript
var path = require('path');
var express = require('express');
var RewriteMiddleware = require('express-htaccess-middleware');
var RewriteOptions = {
  file: path.resolve(__dirname, '.htaccess'),
  verbose: (process.env.ENV_NODE == 'development'),
  watch: (process.env.ENV_NODE == 'development'),
};

var app = express();
app.use(RewriteMiddleware(RewriteOptions));
app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});
```

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

---
_Source: https://npm.io/package/@aredridel/express-htaccess-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
