首页 > 解决方案 > 如果不存在默认文档,则 IIS web.config 重写

问题描述

如果没有定义的页面(即) ,我有一个web.config用于 IIS 的部分用于将请求重写到另一个本地文件夹。wwwrootindex.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>

标签: phpiisweb-config

解决方案


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

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

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


推荐阅读