NodeJS Redirect all non-www to www except subdomains
问题 any idea on how i can do this in Express 3.0? As the non-www url is causing very odd problems in different areas of the website. Thanks! 回答1: The answer didn't work for me. I've used the following code (http://redirect-www.org/#nodejs): //REDIRECT www.domain.com TO domain.com app.get ('/*', function (req, res, next){ var protocol = 'http' + (req.connection.encrypted ? 's' : '') + '://' , host = req.headers.host , href ; // no www. present, nothing to do here if (!/^www\./i.test(host)) { next(