Redirect www to root domain

This commit is contained in:
Jonathan Cremin 2014-12-07 18:33:18 +00:00
parent 4c6644b3d6
commit e5a69d684e

10
app.js
View file

@ -48,8 +48,9 @@ app.use(function(req, res, next) {
next();
})
// force SSL
app.get('*', function(req,res,next) {
// force SSL
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
res.redirect("https://" + req.headers['host'] + req.url);
} else if (req.headers['cf-visitor']) {
@ -57,7 +58,12 @@ app.get('*', function(req,res,next) {
} else {
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) {