Created
June 17, 2013 12:39
-
-
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
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.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