S
S
superivankorolev2016-04-05 09:18:36
JavaScript
superivankorolev, 2016-04-05 09:18:36

How to make a redirect between domains - from www.site.ru to site.ru?

I tried everything on the express:

console.log(req.headers.host,req.url);
  if(req.headers.host.substr(0,4)=='www.'){
    res.writeHead(302, {
      'Location': req.headers.host.substr(4)
    });
    res.end();
    //res.redirect(req.headers.host.substr(4));//+req.url
    console.log('redirect');
  }else next();

As a result, redirect simply loops into recursion and Google Chrome does not load the page...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2016-04-05
@superivankorolev

+ there is no point in doing a standard thing in an abnormal place.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question