【问题标题】:Remove .html extension from url using web.config only for urls that have .html and not home page使用 web.config 从 url 中删除 .html 扩展名,仅适用于具有 .html 而不是主页的 url
【发布时间】:2020-09-28 20:19:02
【问题描述】:

我有一个用于我的网站托管的 Plesk 帐户。我对 web.config 文件一无所知,但我正在尝试从我的 URL 中删除 .HTML 扩展名。我尝试了一个解决方案(稍后在帖子中编写),但它对除主页之外的所有 URL 都非常有效。我的主页显示以下错误:

“/”应用程序中的服务器错误。

运行时错误

(上面的错误中有更多的文字,但我试图使问题尽可能简短)

当我使用www.xyz.com 时,它会显示错误。当使用www.xyz.index.html 时,它可以正常工作,但是我看到的 URL 变成了www.xyz.index,这看起来令人不快。请参考下面的这篇文章,如果可以的话,请帮助我解决问题!

Remove HTML extension with web config permanently

作为上述帖子的最佳答案编写的代码,也是我正在使用的代码:

<configuration>   
    <system.webServer>   
        <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>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: web web-config plesk


    【解决方案1】:

    啊,我明白了。要么是你忘了放/,要么是文件夹,要么是你用了很多域。

    【讨论】:

    • 嗨!我只使用一个域名。您能否向我解释一下 / 或文件夹可能产生的影响?
    • A/可以改。例如,它可能是 example.com/file-1.html/file-1.html>。然后你可以把它改成 example.com/file-1/file-1.html>。一个解决方案是做 example.com/file-1/file-1> (重命名 / 属性!)
    • 如果您建议我在主页上添加后缀,那么这不是我想要的解决方案。我知道 www.xyz.com/home 会起作用,但我不想这样做。我希望它只是 www.xyz.com,其他页面为 www.xyz.com/abc
    • 欢迎来到 SO!请阅读tourHow do I write a good answer?
    猜你喜欢
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 2015-06-20
    • 2022-03-04
    • 1970-01-01
    • 2017-05-08
    • 2014-11-23
    • 2014-03-21
    相关资源
    最近更新 更多