首页 > 解决方案 > IIS URL重写为html而不是同名的子目录

问题描述

我在 IIS 上的 jekyll 生成的静态网站指向子目录,而不是同名的实际 html 文件(都在根目录中)。我如何能够更改 web.config 以便它将重定向/重写到 html?

我正在 IIS 上部署一个 jekyll 生成的静态网站。我已经搜索了互联网,现在 URL 不需要默认的 .html 扩展名。我在 Web.Config 中使用了以下代码来删除 html 扩展名:

<rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
    <match url="^([a-z0-9/]+).html$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Redirect" url="{R:1}" />
</rule>

<rule name="RewriteHTML" enabled="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="{R:1}.html" />
</rule>

这是我的根示例:

-----
|---    
|---   
|          |---1.html
|---/sub---|---2.html
|          |---3.html
|
|---index.html
|
|---sub.html
|
|
|---noExtension.html
|
|
|
-----

我现在所取得的成就是:

http://www.example.com/ =====> index.html

http://www.example.com/noextension =====> noextension.html

http://www.example.com/sub =====> /sub ** 代替 sub.html **

http://www.example.com/sub/1 =====> /sub/1.html

我希望将 urlhttp://www.example.com/sub定向到 sub.html 而不是目录。

** PS 我不认为我可以更改文件结构,因为它是由 jekyll 生成的。并且需要 IIS。没有 Apache/nginx **

如果有人可以帮助我,那将是合适的!

干杯!

标签: iisurl-rewritingjekyll

解决方案


推荐阅读