我目前正在运行带有 IIS 8.5 的 Windows Server 2012 R2 和在 PHP 5.5 上运行的 Phalcon 2.0.8。
我有一个重写规则(使用从 Phalcon 导入的基本 .htaccess 文件)并且重写工作正常。但是,我在名为 APPLICATION_ENV 的重写模块中创建了一个系统变量,并将其附加到具有暂存值的重写。
如果我查看除/public 主索引之外的任何页面,则该值有效——暂存被正确地引入。但是,在索引上,它不应用该值。为什么?
编辑:这是我当前的 web.config 文件,其中包含所有内容。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?_url=/{R:1}" appendQueryString="true" />
<serverVariables>
<set name="APPLICATION_ENV" value="staging" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
最佳答案
问题(如果我理解正确的话):
为什么访问/public
时没有设置APPLICATION_ENV
?
答案: 原因是你指定了一个异常(exception):
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
这意味着如果存在与访问路径匹配的目录,则不会执行重写。在您的情况下,您访问 /public
并且这不是 Controller 的名称,而是实际目录的名称。因此,直接提供其索引文件。恰好与重写目标相同,纯属巧合。
关于php - Phalcon, IIS, 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33207333/