301 redirect code for nodejs express
- tervancovan

- 2019년 1월 18일
- 1분 분량
google SEO 진행시 선호 url 선택 문제가 생겨
nodejs express 에서
toonsquare.co 를 www.toonsquare.co 로 redirection 작업을
아래와 같이함
app.use((req, res, next) => { var host = req.get('Host'); debug(host); debug(req.originalUrl); if (host === 'toonsquare.co') { return res.redirect(301, 'http://www.toonsquare.co' + req.originalUrl); }else if(host === 'toonsquare.co:8080'){ return res.redirect(301, 'http://www.toonsquare.co:8080' + req.originalUrl); } return next(); });


댓글