如何使用web.config在IIS中使用特定的子域重定向到主域?

时间:2017-07-26 10:59:09

标签: iis iis-7 web-config

目前我有一个子域https://blog.example.com,我想将其重定向到https://example.com/blog。我正在使用在IIS 7服务器上运行的Craft CMS。

我尝试了下面提到的代码,但它不起作用:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
         <rewrite>
             <rules>
                <rule name="Redirect blog to new url" enabled="true" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern=".*" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/blog/{R:0}" />
                </rule>
             </rules>
         </rewrite>
    </system.webServer>
</configuration>
  

更新:添加目录结构

enter image description here

1 个答案:

答案 0 :(得分:1)

问题似乎与您指定的条件有关。您当前的模式是。* ,这将导致无限循环。更改模式以检查特定URL,如下所示。

<xsl:template match="Name">
    <Category Name="{@Value}" ParentCategoryId="{following-sibling::ParentCategory[1]/@ID}">
        <xsl:copy-of select="../@ID|../@LowPic|../@ThumbPic|../@UNCATID|@langid" />
    </Category>
</xsl:template>  

我试过这个,它对我有用。转到http://blog.kaushal.co.in

如果您需要对网址重写规则进行问题排查,请为您的网站启用失败的请求跟踪。有关详细信息,请参阅此处:Using Failed Request Tracing to Trace Rewrite Rules

<强>更新

重写规则需要添加到网站的根目录&#34; /&#34; 中的117072616095252,而不是其中一个子网站的web.config中文件夹。