簡體   English   中英

如何使用Express JS路由器在Node JS項目中進行301重定向?

[英]How to make 301 redirect in Node JS project with Express JS router?

我有主題搜索和Google,並且所有搜索引擎都希望具有301重定向,我的項目是在Heroku Cloud使用節點服務器上設置的,並且在將301“ domain.com”重定向到“ www.domain.com”時遇到了問題。

所以我發現了問題並解決了,在我的情況下, request.headers.host只是domain.com而已,其功能是:

app.get('/', function(request, response, next) {
if(request.headers.host =="domain.com") {
    response.writeHead(301, {'Location':'http://www.domain.com'+ request.url, 'Expires': (new Date).toGMTString()});
    response.end();
}
else{
    next();
}})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM