我有 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/