【问题标题】:redirect url from web.config file not working properly从 web.config 文件重定向 url 无法正常工作
【发布时间】:2019-06-25 22:13:20
【问题描述】:

我想删除我的 html 扩展名,但在目录中使用时失败。 link1 我的网站工作正常,但其他目录链接不能正常工作。 link2

我想删除这个链接末尾的html扩展

http://mremind.com/products-services/credentialing.html

但是在我重写之后

http://mremind.com/products-services/credentialing/ 这不起作用。

在 stackover flow other question 我找到了我的问题的解决方案,但它无法正常工作。

我在 web.config 文件中的解决方案是

<rewrite>
    <rules>
        <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="true">
            <match url="^(.*).html"/>
            <conditions logicalGrouping="MatchAny">
                <add input="{URL}" pattern="(.*).html"/>
            </conditions>
            <action type="Redirect" url="{R:1}"/>
        </rule>
    </rules>
</rewrite>

【问题讨论】:

    标签: asp.net iis url-rewriting web-config


    【解决方案1】:

    我认为你想要的需要另一个重写规则。您从 credentialing.html 重定向到 credentialing,但该文件不存在,因此您可能得到 404。 您需要的是一条规则,将 .html 扩展名再次添加为重写,以便 IIS 可以再次找到该文件。

    <rule name="No html ext" stopProcessing="true">
      <match url="^([a-z0-9-_/]+)$" ignoreCase="true" />
      <action type="Rewrite" url="{R:1}.html" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2015-08-09
      • 2014-07-01
      • 2015-12-21
      • 2017-03-04
      相关资源
      最近更新 更多