Created
March 24, 2022 04:58
-
-
Save matheusdavidson/70584a8d090ed63590b8b4f28d61127b to your computer and use it in GitHub Desktop.
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
//... start of the script | |
server.all(/.*/, function (req, res, next) { | |
// | |
// Get host | |
const host: any = req.header('host'); | |
// | |
// redirect non www to www | |
else if (!host.includes('www')) { | |
res.redirect(301, 'https://www.' + host + req.url); | |
} | |
// | |
// redirect http to https | |
else if (!req.secure) { | |
res.redirect(301, 'https://' + host + req.url); | |
} | |
// | |
// it's fine now | |
else { | |
next(); | |
} | |
} | |
//... end of the script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment