[英]Apache .htaccess rewrite rule to IIS FastCGI web.config rule problems
所以我有一個自定義的 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”,它就可以工作。
我修好了它。 這兩個 web.configs 相互沖突。 所以,我完全放棄了 public/web.config。
我的根 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="(.*)" />
<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="public/index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
打開iis選擇/website/public open URL Rewrite Import Rules UI,注釋掉rewrite base /website/public這一行,導入剩下的規則。 這將導致重寫規則保存到位於該目錄的 web.config 文件中。 這將為您提供與 apache 上的重寫基礎相同的行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.