javascript - How to redirect from one domain to another in Express? - Stack Overflow

To be precise, my website is currently being redirected to appID-appspotHow can I force a redirect to m

To be precise, my website is currently being redirected to appID-appspot

How can I force a redirect to my custom domain ?

That is, when gets "appID-appspot", redirect to "custom domain".

To be precise, my website is currently being redirected to appID-appspot.

How can I force a redirect to my custom domain ?

That is, when gets "appID-appspot.", redirect to "custom domain".

Share Improve this question asked Feb 21, 2017 at 12:43 Coder1000Coder1000 4,50110 gold badges38 silver badges87 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can use regular expression route matching of express.

app.get(/appID-appspot./, function (req, res) {
  res.redirect('custom_domain');
}

/appID-appspot./

matches the url and redirects to customdomain, if the URL contains that part.

Add the above to top of the routes so that it gets redirected first.

You should use res.redirect(301, 'http://example.');

Full example:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745421897a4627002.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信