web-config - web.config 将 2 条规则合并为 1 条

标签 web-config rules

我有 3 条规则作为基础 1.隐藏HTML扩展 2. 重定向html 3.非www到www。

但是,当用户转到 http://example.net/content -> http://www.example.net/content.html -> http://www.example.net/content

<rule name="Hide .html ext">
      <match ignoreCase="true" url="^(.*)"/>
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
        <add input="{REQUEST_FILENAME}.html" matchType="IsFile"/>
      </conditions>
      <action type="Rewrite" url="{R:0}.html"/>
</rule>
<rule name="Redirecting .html ext" stopProcessing="false">
      <match url="^(.*).html"/>
      <conditions logicalGrouping="MatchAny">
        <add input="{URL}" pattern="(.*).html"/>
      </conditions>
      <action type="Redirect" url="{R:1}"/>
</rule>
<rule name="Redirect to www" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example.net$" />
      </conditions>
      <action type="Redirect"
        url="{MapProtocol:{HTTPS}}://www.example.net/{R:1}" />
</rule>

我有一个特殊要求,只让它对此页面进行 1 301 重定向。我尝试了多种方法但没有结果。我可以尝试这个的最佳方法是什么?

谢谢!

最佳答案

添加为第二条规则:

<rule name="Redirect to www + .html ext" stopProcessing="true">
      <match url="(.*)" />
      <conditions trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example.net$" />
        <add input="{URL}" pattern="(.*).html"/>
      </conditions>
      <action type="Redirect"
        url="{MapProtocol:{HTTPS}}://www.example.net/{R:1}" />
</rule>

关于web-config - web.config 将 2 条规则合并为 1 条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55794186/

相关文章:

c# - 在 web.config 中转义引号和 @

ASP.NET 如何在 web.config 中添加程序集?

visual-studio-2010 - Visual C++ 2010 的惰性 C++ (LZZ) 规则文件

linux - udev .rules 文件以每个用户的本地身份运行?

asp.net - 使用多个版本的 nlog

asp.net - 无法使用 URL 重写出站规则更改 IIS 响应代码

asp.net-mvc - web.config 中的错误 - MVC

java - SonarAnalyzer Java 规则

database - Drools:在数据库中存储规则

python - 理解 Scrapy 的 CrawlSpider 规则