NodeJS将所有非www重定向到www(子域除外) [英] NodeJS Redirect all non-www to www except subdomains
本文介绍了NodeJS将所有非www重定向到www(子域除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于如何在Express 3.0中做到这一点的任何想法?由于非www网址在网站的不同区域造成了非常奇怪的问题.
any idea on how i can do this in Express 3.0? As the non-www url is causing very odd problems in different areas of the website.
谢谢!
推荐答案
所以我找到了另一个问题的答案.
So i found the answer from another question.
对不起,您之前没有搜索
Sorry for not searching before
app.get ('/*', function (req, res, next){
if (!req.headers.host.match(/^www\./)){
res.writeHead (301, {'Location': 'http://mysite.com'});
}else{
return next();
}
});
这篇关于NodeJS将所有非www重定向到www(子域除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文