admin管理员组

文章数量:1426804

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');
});

本文标签: javascriptHow to redirect from one domain to another in ExpressStack Overflow