【问题标题】:Change Host Header in rewrite rule IIS在重写规则 IIS 中更改主机标头
【发布时间】:2021-12-28 09:34:41
【问题描述】:

我有以下重写规则:

<rule name="myTest_rewrite" stopProcessing="true">
    <match url="^(contacto.*)$" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^(www)\.(myfirstsite)\.com" />
    </conditions>
    <action type="Rewrite" url="https://abc.mysfirstsite.com/{R:0}" appendQueryString="true />
</rule>

问题

  1. 当请求从www.myfirstsite.com 重写为abc.mysfirstsite.com 时,当请求重写为abc.mysfirstsite.com 时,主机头会是什么?是abc.mysfirstsite.com 还是www.myfirstsite.com

  2. 如果上面问题中的主机头是abc.mysfirstsite.com,那么如何通过我的重写规则将其更改为www.myfirstsite.com

【问题讨论】:

标签: c# .net curl url-rewriting azure-web-app-service


【解决方案1】:

以下是设置 HTTP 请求头和 IIS 服务器变量的示例

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>URL Rewrite Module v2 Test - Setting Server Variables</title>
</head>
<body>
 <h1>Setting HTTP request header and a server variable with URL Rewrite Module v2</h1>
 <p>The value of the Language cookie is <strong><%=( Request.Cookies["Language"] != null ) ? Request.Cookies["Language"].Value : "Cookie not set" %></strong></p>
 <p>The originally requested URI is <strong><%= HttpUtility.HtmlEncode( Request.ServerVariables["ORIGINAL_URI"] ) %></strong></p>
</body>
</html>

这里是documentation,其中包含有关在 HTTP 标头中创建重写规则的完整信息。也可以参考SO 提供相关信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 2017-05-17
    • 1970-01-01
    • 2017-08-09
    • 2020-10-22
    • 2018-02-12
    相关资源
    最近更新 更多