因此,我有一个自定义的PHP MVC框架,该框架在Apache中可以很好地工作,但是很难适应IIS 10 FastCGI。
这是我的结构:
/website/
- htaccess / web.config
- app folder -> Libraries (Core, Controller, Database), Controllers, Models, Views, Includes, Helpers, etc
- public folder -> css, js, index.php, htaccess / web.config
root htaccess看起来像这样:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
将其翻译为该web.config:
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
因此,点击路由到“网站/公共”的“网站”完全正常。
问题出在公共web.config。这是它的htaccess:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /website/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
Web.config翻译:
<rule name="Imported Rule 1-1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<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?url={R:1}" appendQueryString="true" />
</rule>
例如,现在我应该可以访问“网站/职位”或“网站/职位/列表/ 0”。在Apache上工作正常,但在IIS上却收到404。两天后无法解决。
感谢任何提示!谢谢。
[编辑]有什么方法可以追踪请求?我已经尝试根据此链接https://wengier.com/debugging-iis-rewrite-rules/在IIS中进行“失败的请求跟踪”,但是IIS似乎没有向日志输出任何404错误。我的FRT设置似乎缺少链接中所示的“ RequestRouting”和“ Rewrite”选项。
打开iis选择/ website / public打开URL重写导入规则UI,注释掉重写的/ website / public行,然后导入其余规则。这将导致重写规则保存到该目录下的web.config文件中。这将为您提供与基于Apache的重写基础相同的行为。