[英]How to redirect from one domain to another in Express?
确切地说,我的网站目前已重定向到appID-appspot.com
如何强制重定向到我的自定义域?
也就是说,当获取“ appID-appspot.com”时,重定向到“自定义域”。
您可以使用express的正则表达式路由匹配。
app.get(/appID-appspot.com/, function (req, res) {
res.redirect('custom_domain');
}
/appID-appspot.com/
如果网址包含该部分,则匹配该url
并重定向到customdomain。
将以上内容添加到路由的顶部,以便首先将其重定向。
您应该使用res.redirect(301, 'http://example.com');
完整示例:
router.get('/', function(req, res){
res.redirect(301, 'custom domain');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.