Last active
August 29, 2015 14:03
-
-
Save tdharris/3d02723acf1827829093 to your computer and use it in GitHub Desktop.
Cut http://www. from request so browser URL shows just request.url (http://www.domain.com --> domain.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function(request, response, next) { | |
var newHost = request.host.replace(/[http*:\\]*www./, ''); | |
if (request.host != newHost) { | |
// 301 is a "Moved Permanently" redirect. | |
res.redirect(301, request.protocol + "://" + newHost + request.url); | |
} else { | |
next(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment