如何使用ExpressJS检查主机? [英] How to check the HOST using ExpressJS?
本文介绍了如何使用ExpressJS检查主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须检查http请求的 HOST
,如果它等于 example.com
或 www.example.com
,我必须进行301重定向。
I have to check the HOST
of the http request, if it's equal to example.com
or www.example.com
, I have to do a 301 redirect.
我如何使用Node.js和Express Web Framework?
How can I do this using Node.js and Express Web Framework?
推荐答案
使用
req.headers.host;
或
req.header('host');
两者都会返回主机名。例如 localhost:3000
Both will return you host name. e.g localhost:3000
这篇关于如何使用ExpressJS检查主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文