Redirect www to root domain
This commit is contained in:
parent
4c6644b3d6
commit
e5a69d684e
1 changed files with 8 additions and 2 deletions
10
app.js
10
app.js
|
@ -48,8 +48,9 @@ app.use(function(req, res, next) {
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
|
|
||||||
// force SSL
|
|
||||||
app.get('*', function(req,res,next) {
|
app.get('*', function(req,res,next) {
|
||||||
|
// force SSL
|
||||||
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
|
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
|
||||||
res.redirect("https://" + req.headers['host'] + req.url);
|
res.redirect("https://" + req.headers['host'] + req.url);
|
||||||
} else if (req.headers['cf-visitor']) {
|
} else if (req.headers['cf-visitor']) {
|
||||||
|
@ -57,7 +58,12 @@ app.get('*', function(req,res,next) {
|
||||||
} else {
|
} else {
|
||||||
req.userProtocol = "http"
|
req.userProtocol = "http"
|
||||||
}
|
}
|
||||||
next();
|
// redirect www
|
||||||
|
if (req.headers.host.match(/^www/) !== null ) {
|
||||||
|
res.redirect(req.userProtocol + '://' + req.headers.host.replace(/^www\./, '') + req.url);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue