# hapi-redirects

> Hapi redirects

Latest version **7.1.2** (published 2021-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-redirects
pnpm add hapi-redirects
yarn add hapi-redirects
bun add hapi-redirects
```

## 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 | 7.1.2 |
| Published | 2021-02-19 |
| First published | 2014-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 25.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | First+Third |
| Maintainers | jga, dawnerd, ecwillis, orthagonal1, alaguna, aleperez92 |

## Links

- npm: https://www.npmjs.com/package/hapi-redirects
- Repository: https://github.com/firstandthird/hapi-redirects
- Issues: https://github.com/firstandthird/hapi-redirects/issues
- npm.io page: https://npm.io/package/hapi-redirects

## Dependencies (3)

- [call](https://npm.io/package/call.md) ^5.0.3
- [useragent](https://npm.io/package/useragent.md) ^2.3.0
- [query-string](https://npm.io/package/query-string.md) ^6.5.0

## Recent versions

- 7.1.2 (latest) — 2021-02-19
- 7.1.0 — 2019-05-07
- 7.0.3 — 2019-04-08
- 7.0.2 — 2019-03-08
- 7.0.1 — 2019-02-02
- 7.0.0 — 2018-09-26
- 6.2.3 — 2018-02-28
- 6.2.2 — 2018-02-21
- 6.2.1 — 2018-02-21
- 6.2.0 — 2018-02-02
- 6.1.0 — 2018-01-19
- 6.0.0 — 2017-12-18
- 5.0.0 — 2017-10-23
- 4.2.0 — 2017-08-15
- 4.1.0 — 2017-04-05
- … 6 more at https://npm.io/package/hapi-redirects/versions

## README

hapi-redirects [![Build Status](https://travis-ci.org/firstandthird/hapi-redirects.svg?branch=master)](https://travis-ci.org/firstandthird/hapi-redirects)
==============

Hapi plugin for redirects


## Installation

`npm install --save hapi-redirects`

## Usage

```js
server.register([
  {
    plugin: require('hapi-redirects'), options: {
      log: true,
      log404: true,
      // can match any valid hapi route specifier including route params and redirect to the specified value:
      redirects: {
        "/shortlink": "/a/much/longer/path?search=longer",
        '/post/(.*)/': '/cats',
        '/*': '/newtest',
        '/cats302': {
          destination: '/cats',
          statusCode: 302 // can overload the type of HTTP redirect
        },
        "/cats/cute": "/search?animal=cat&type=cute"
      },
      vhosts: {
        'cats.com': {
          '/cats-also': '/cats',
        }
      },
      // can be passed a function that dynamically generates new route
      // redirections every time an HTTP request is handled:
      getRedirects(pluginOptions, callback) {
        // the first parameter contains the plugin options:
        if (pluginOptions.log) {
          server.log(['redirect', 'cats'], 'cats');
        }
        // callback takes any error as the first param and a list of route redirections as the second:
        return callback(null, [
          {
            // this will HTTP 302 redirect every incoming request to '/dynamic-cats' to a different destination:
            '/dynamic-cats': {
              destination: '/cats/' + Math.random(),  
              statusCode: 302
            },
          }
        ]);
      }
    }
  }}
], function(err) {
});
```

---
_Source: https://npm.io/package/hapi-redirects · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
