代码之家  ›  专栏  ›  技术社区  ›  Kaiser Wilhelm

在Express请求中更改主机名

  •  1
  • Kaiser Wilhelm  · 技术社区  · 9 年前

    有没有办法在express web服务器上更改请求的主机名?假设我有一个可以通过以下URL点击的web服务器:

    https://servername.company.location.com/login 和 https://servername/login

    有没有办法路由所有使用“ https://servername/login “收件人” “?我知道这可以通过apache通过RewriteRule和.htaccess文件来完成。

    谢谢

    1 回复  |  直到 9 年前
        1
  •  2
  •   whitfin    9 年前

    您可以使用 res.redirect

    // purely an example, implementation is up to you
    app.get('/login', function (req, res) {
        res.redirect('https://servername.company.location.com/' + req.path);
    });
    
    推荐文章