express-naked-redirect
v0.1.9
Published
expressNakedRedirect is a middleware for Express that redirects naked(root domain) request to www or its reverse.
Downloads
4,503
Maintainers
Readme
express-naked-redirect
expressNakedRedirect is a middleware for Express that redirects naked(root domain) request to www or its reverse.
Installation
$ npm install express-naked-redirect --save
Features
- Redirect naked(root domain, non-www) request to www.
- Redirect www request to naked(root domain, non-www).
- Redirect naked(root domain, non-www) request to specific subdomain.
- Redirect specific subdomain request to naked(root domain, non-www).
- Redirect http request to https(or specific protocol).
Usage
Redirect naked to www
It allows you to redirect http://domain.tld to http://www.domain.tld
app.use(require('express-naked-redirect')())
Redirect www to naked
It allows you to redirect http://www.domain.tld to http://domain.tld
app.use(require('express-naked-redirect')(true))
or
app.use(require('express-naked-redirect')({
reverse: true
}))
Redirect naked to specific subdomain
It allows you to redirect http://domain.tld to http://sub.domain.tld
app.use(require('express-naked-redirect')('sub'))
or
app.use(require('express-naked-redirect')({
subDomain: 'sub'
}))
Redirect specific subdomain to naked
It allows you to redirect http://sub.domain.tld to http://domain.tld
app.use(require('express-naked-redirect')(true, 'sub'))
or
app.use(require('express-naked-redirect')({
reverse: true,
subDomain: 'sub'
}))
Redirect http to https
It allows you to redirect http://domain.tld to https://www.domain.tld
app.use(require('express-naked-redirect')({
subDomain: 'www',
https: true
}))
or
app.use(require('express-naked-redirect')({
subDomain: 'www',
protocol: 'https'
}))
Do not redirect specific paths
If you do not want to redirect specific paths, add except
option. It requires url-pattern
library separately.
app.use(require('express-naked-redirect')({
reverse: true,
subDomain: 'sub',
except: [
'/foo/bar',
'/foo/bar/:id'
]
}))