[英]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.