【问题标题】:IIS web.config : Rewrite URL file as subdomainIIS web.config:将 URL 文件重写为子域
【发布时间】:2019-12-23 16:46:53
【问题描述】:

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

实际网址: sudomain.mydomain.com/legal.html

希望的网址: 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”是什么意思?你希望浏览器地址栏最后显示什么?在说清楚之前,我建议你不要猜测重写或重定向。

标签: url iis url-rewriting web-config


【解决方案1】:

为了实现这一点, 我刚刚为我的网站注册了两个 CNAME。 FQDN:subdomain.mydomain.com FQDN:legal.mydomain.com

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

只要确保它们都可以在网络浏览器中访问。

然后我应用以下重写规则

  <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 以获取响应内容。

请记住,即使您只是将其用作掩码,也始终需要在 DNS 中注册 legal.mydomain.com。

如果您的网站转发公共互联网,请记得购买 legal.domain.com 的域名。

【讨论】:

    猜你喜欢
    • 2017-08-24
    • 2012-12-25
    • 1970-01-01
    • 2017-08-23
    • 2018-08-28
    • 2012-04-11
    • 1970-01-01
    • 2011-05-23
    • 2016-09-23
    相关资源
    最近更新 更多