Skip to content

Instantly share code, notes, and snippets.

@htsh
Created June 17, 2013 12:39
Show Gist options
  • Save htsh/5796569 to your computer and use it in GitHub Desktop.
Save htsh/5796569 to your computer and use it in GitHub Desktop.
non-coffee version of user blakematrix's method to remove leading 'www''s from urls in express
app.get('/*', function(req, res, next) {
if (req.headers.host.match(/^www\./) != null) {
res.redirect("http://" + req.headers.host.slice(4) + req.url, 301);
} else {
next();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment