【问题标题】:How to remove the .html part of the URL on Azure?如何在 Azure 上删除 URL 的 .html 部分?
【发布时间】:2017-04-24 12:32:29
【问题描述】:

说,我想把这个:www.example.com/homepage.html 变成这个www.example.com/homepage

为了实现这一点,我应该在 Azure 门户或配置中进行哪些更改?

【问题讨论】:

  • 我不认为这是您在门户中配置的内容。相反,您可以在您的应用程序中配置它。是 ASP.NET、Node、...?

标签: azure


【解决方案1】:

您可以将此代码块放在您的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>

这将从 每个 html 文件中删除 .html 扩展名。因此,例如,如果您打开一个名为 index.html 的文件,它将显示为索引,如果您请求文件索引,它将显示 index.html 文件(不会显示扩展名)。

这在 Azure 和 IIS 上都有效,因此如果将来您要迁移到 IIS,则无需更改任何内容即可。

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多