【发布时间】:2012-10-03 17:31:43
【问题描述】:
我一直在尝试使用根文件夹中的以下 web.config 设置来让重写规则在 CakePHP 的 IIS 上工作:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="app/webroot/{R:1}" />
</rule>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="webroot/" />
</rule>
<rule name="Imported Rule 4" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="webroot/{R:1}" />
</rule>
<rule name="Imported Rule 5" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
所有的 CSS、JS 和其他文件都可以正常工作。与在主页中加载一样,但其他页面如 /pages/about 仅显示 404!
编辑:IIS 中设置的屏幕截图:
有什么问题?谢谢
【问题讨论】:
-
IIS 404 还是 CakePHP 404?如果是后者,则在 core.php 中将 debug 设置为 2。
-
IIS 404 在蓝屏中显示为红色文本。
-
如果将 IIS webroot 设置为 app/webroot 目录,则可以放弃规则 1-4 并缩小问题范围。
-
据我所知,如果 REQUEST_FILENAME 行正常工作,您可能需要最后一行中 index.php 的完整相对路径(即 app/webroot/index.php) - 除非您听从我上面的建议。