【发布时间】:2019-11-28 23:19:31
【问题描述】:
所以我有一个自定义的 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
根 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”选项。
[EDIT2] 两个 web.config 文件之间似乎存在冲突。如果我禁用根 web.config 文件,然后输入“website/public/jobs”(而不是“website/jobs”,它会起作用。
【问题讨论】:
标签: apache .htaccess iis url-rewriting web-config