IIS web.config:将URL文件重写为子域

问题描述 投票:0回答:1

我正在尝试使用web.config文件重写我的网址。

实际URL: sudomain.mydomain.com/legal.html

WiURL URL: legal.mydomain.com

我已经隐藏了html扩展名。

<rule name="Hidehtml" enabled="true">
      <match ignoreCase="true" url="Legal" />
          <conditions>
             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
             <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
           </conditions>
       <action type="Rewrite" url="Legal.html"/>
</rule>

我看到子文件夹可以进行这种重写,但是我想知道文件是否可以进行这种重写。我正在尝试此操作,但它给了我DNS错误。

 <rule name="testrule" stopProcessing="true">
        <match url="legal(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="mydomain.com" />
        </conditions>
        <action type="Redirect" url="http://legal.mydomain.com" />
    </rule>

我想知道我是否没有丢失任何东西,也许也需要重定向吗?

感谢您的帮助!

url iis url-rewriting web-config
1个回答
0
投票

我刚刚为我的网站注册了两个CNAME。FQDN:subdomain.mydomain.comFQDN:legal.mydomain.com

enter image description here

然后将它们应用于我的IIS站点。

enter image description here

只需确保它们都可以在Web浏览器中访问。

然后我应用以下重写规则

  <rules>
                <rule name="testrule" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{URL}" pattern="^/legal\.[a-zA-Z]+" />
                        <add input="{HTTP_HOST}" pattern="subdomain.candy.com" />
                    </conditions>
                    <action type="Redirect" url="http://legal.candy.com" />
                </rule>
                <rule name="rewrite rule">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="legal.candy.com" />
                        <add input="{URL}" pattern="^(/)?$" />
                    </conditions>
                    <action type="Rewrite" url="http://subdomain.candy.com/legal.html" />
                </rule>
            </rules>

[当您访问sudomain.mydomain.com/legal.html时,请求将被重定向到legal.mydomain.com/,而legal.mydomain.com将被重写回/legal.html以获取响应内容。

[请记住,即使您仅将Legal.mydomain.com用作掩码,也必须在DNS中进行注册。

如果您的网站正在转发公共互联网,请记住也要为legal.domain.com购买域名。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.