简体   繁体   中英

Change Host Header in rewrite rule IIS

I have the following rewrite rule:

<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>

Questions

  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 ? Will it be abc.mysfirstsite.com or www.myfirstsite.com ?

  2. If the host header in above question is abc.mysfirstsite.com , then how do I change it to www.myfirstsite.com through my rewrite rule?

Below is the example in setting up HTTP request headers and IIS server variables

<%@ 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>

Here is the documentation with complete information about creating rewrite rule in HTTP headers. and also you can refer the SO with related information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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