To be precise, my website is currently being redirected to appID-appspot.com
How can I force a redirect to my custom domain ?
That is, when gets "appID-appspot.com", redirect to "custom domain".
You can use regular expression route matching of express.
app.get(/appID-appspot.com/, function (req, res) {
res.redirect('custom_domain');
}
/appID-appspot.com/
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.com');
Full example:
router.get('/', function(req, res){
res.redirect(301, 'custom domain');
});
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.