我正在 Windows Server 2012 下的 IIS8 上執行基於 PHP 的應用程式。
這是我的 web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="https://my.website.co.uk" />
<rewrite>
<rules>
<rule name="Hide Yii Index" stopProcessing="true">
<match url="." />
<action type="Rewrite" url="index.php" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" path="/errors/401.htm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
當我嘗試在不提供憑證的情況下查看網站時,我看到的只是一個空白頁面。頁面的源代碼也是完全空白的 - 沒有單一 html 標籤。
我有什麼想法可以讓這個工作嗎?
答案1
想想你在這裡做什麼。您是說,如果使用者未經過正確身份驗證,則向使用者顯示其他頁面。但這個(401)頁面只能顯示給經過驗證的使用者。因此 IIS 不允許向使用者顯示該頁面,而是顯示空白頁面。
至少有兩種方法可以解決此問題,將 httpErrors 更改為:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" path="errors\401.htm" responseMode="File" />
</httpErrors>
透過將 responseMode 變更為File
,iis 不再執行 URL,而是載入檔案內容並將其傳送給使用者。無論身份驗證狀態如何,這始終有效。該路徑是相對於網站根目錄的。
另一個選項是將 web.config 新增到錯誤資料夾中,並允許對此目錄進行匿名驗證,畢竟它只有錯誤頁面。