如果不存在默认文档,则重写 IIS web.config



我有一个用于 IIS 的web.configwwwroot如果没有定义的页面(即index.php(。

因此,像:www.blah.net/something/index.php这样的网址显示的页面正确。 但是,www.blah.net/something/重写到另一个 URL 并忽略该目录中的index.php

<configuration>
<system.webServer>
<defaultDocument enabled="true" />
<rewrite>
<rules>
<rule name="RewriteAll" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="_h5ai/public/index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<caching enabled="false" enableKernelCache="true" />
</system.webServer>
</configuration>

相当简单,只需添加一个条件来检查文件是否存在。

<conditions>
<add input="{Document_Root}/{REQUEST_URI}/index.php" matchType="IsFile" negate="true" />
</conditions>

此外,请在清除本地浏览器缓存后或在浏览器的隐身窗口中验证结果.
如果问题仍然存在,请随时告诉我。

我认为您需要告诉IIS您的默认文档是什么。 替换行

<defaultDocument enabled="true" />

<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="index.htm" />
<add value="default.php" />
<add value="default.htm" />        
</files>
</defaultDocument>

IIS 将按列出的顺序检查默认文档部分中列出的所有文件名,您可以根据需要拥有任意数量的文件名。<clear />行指示 IIS 忽略标准服务器设置。 (如果您不指定任何默认文件,我认为它将查找"默认.htm","默认.aspx"和"默认.asp"。

最新更新