简体   繁体   中英

How show I handle a 301 redirect from an existing page to another page in my index.js file

Hi everyone and happy friday. Im just trying to find out what is the best way to handle a 301 redirect in node from an existing file to another file. Lets say I have a file that exists called /contact

router.get('/contact', function (req, res) {
  res.render('contact');
});

If I want to redirect users from that file onto a new route on wordpress, which is /to/contact should I do this?

router.get('/to/contact', function (req, res) {
  res.redirect(301).('contact');
});

I tried doing research on this but not sure what to do for a explicit redirect like here. Its a bit confusing. Thanks!

You've got the two routes confused:

router.get('/contact', function (req, res) {
  res.redirect(301, '/to/contact');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM