Last active
January 2, 2016 10:39
-
-
Save fiveisprime/8291866 to your computer and use it in GitHub Desktop.
Redirect Express to www.
This file contains hidden or 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.all(/.*/, function(req, res, next) { | |
| var host = req.header('host'); | |
| if (host.match(/^www\..*/i)) return next(); | |
| res.redirect(301, 'http://www.' + host); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment