繁体   English   中英

在重写规则 IIS 中更改主机 Header

[英]Change Host Header in rewrite rule IIS

我有以下重写规则:

<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. When the request rewrites from www.myfirstsite.com to abc.mysfirstsite.com , what would be the host header when request rewrites to abc.mysfirstsite.com ? abc.mysfirstsite.com还是www.myfirstsite.com

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

下面是设置 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>

这是有关在 HTTP 标头中创建重写规则的完整信息的文档 您也可以参考SO以及相关信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM