Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/john-doherty/express-seo-redirects
Simple config based 301/302 redirects for express
https://github.com/john-doherty/express-seo-redirects
express redirect seo
Last synced: about 1 month ago
JSON representation
Simple config based 301/302 redirects for express
- Host: GitHub
- URL: https://github.com/john-doherty/express-seo-redirects
- Owner: john-doherty
- License: mit
- Created: 2020-07-24T10:42:53.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-27T10:16:42.000Z (almost 3 years ago)
- Last Synced: 2024-11-09T13:20:06.686Z (about 2 months ago)
- Topics: express, redirect, seo
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-seo-redirects
Simple config based 301/302 redirects for express.
## Install
```bash
npm install express-seo-redirects --save
```## Usage
Add the middleware to your express application before all other routes.
```js
var express = require('express');
var app = express();
var redirects = require('express-seo-redirects');// add middleware with relative path to redirect.json file
app.use(redirects('./redirects.json'));// standard express route
app.get('/', function(req, res) {
res.send('Hello world!');
});
```Create a `redirects.json` file in the root of your project, with a list of redirects:
```json
[
{ "status": 301, "from": "/mobile-barcode-scanner", "to": "/docs/getting-started/mobile" },
{ "status": 301, "from": "/mobile-data-capture-platform", "to": "/" },
{ "status": 301, "from": "/plans", "to": "/pricing" },
{ "status": 301, "from": "/plans-new", "to": "/pricing" }
]
```Each redirect can have 3 parameters:
Property | Type | Required | Description
-------- |:------- |:------------------:|:------------------------------------------
`from` | string | :heavy_check_mark: | Relative URL of incoming request
`to` | string | :heavy_check_mark: | Destination URL
`status` | integer | | HTTP response code _(302 if not provided)_QueryStrings are ignored by default, to match on path and query string pass `app.use(redirects('./redirects.json', true));` as the second param to enable strict mode.
## Contributing
Feel free to contribute, either by [raising an issue](https://github.com/john-doherty/express-seo-redirects/issues) or:
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -m 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request## History
For change-log, check [releases](https://github.com/john-doherty/express-seo-redirects/releases).
## License
Licensed under [MIT License](LICENSE) © [John Doherty](https://twitter.com/mrjohndoherty)