如何在Azure上删除URL的.html部分? [英] How to remove the .html part of the URL on Azure?

查看:41
本文介绍了如何在Azure上删除URL的.html部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我想把这个代码: www.example.com/homepage.html 转到这个 www.example.com/homepage

Say, I want to turn this: www.example.com/homepage.html to this www.example.com/homepage

要实现此目的,我应该在Azure门户或配置中进行哪些更改?

What should I change in my Azure portal or config in order to achieve this?

推荐答案

您可以将此代码块放置在 web.config 文件中.

You could place this block of code in your web.config file.

<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;如果您请求该文件的索引,它将显示为index.html文件(扩展名将不会显示).

This will remove the .html extension from every html file. So, for example, if you open a file called index.html it would be shown as index and if you request the file index it will be shown the index.html file (the extension will not be shown).

这在Azure和IIS上均适用,因此,如果将来将来移至IIS,则可以不做任何更改.

This works both on Azure and on IIS, so if in a future you would move to IIS, you could do without changing anything.

我希望我能帮到你.

这篇关于如何在Azure上删除URL的.html部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆