Skip to content

Instantly share code, notes, and snippets.

@tdharris
Last active August 29, 2015 14:03
Show Gist options
  • Save tdharris/3d02723acf1827829093 to your computer and use it in GitHub Desktop.
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)
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