Created
February 1, 2019 10:25
-
-
Save olegpolyakov/2f25680e9e8ba7069dff40c8cb98b06b to your computer and use it in GitHub Desktop.
Express middleware to ensure that there is no www in the url.
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
function noWww(req, res, next) { | |
if (req.hostname.match(/^www\./) !== null) { | |
res.redirect(301, req.protocol + '://' + req.hostname.replace(/^www\./, '') + req.originalUrl); | |
} else { | |
next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment