简体   繁体   中英

Trying to create a custom error page with IIS (server is using php)

So the title says it. I just cannot get the web.config file working. If anyone knows what I'm doing wrong here it would be nice. http_error_handler.php takes a get request in the url and displays the error according to that.

Contents of web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <remove value="index.php" />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <httpErrors>
            <clear />
            <remove statusCode="403" subStatusCode="-1"></remove>
            <remove statusCode="404" subStatusCode="-1"></remove>
            <remove statusCode="405" subStatusCode="-1"></remove>
            <remove statusCode="408" subStatusCode="-1"></remove>
            <remove statusCode="500" subStatusCode="-1"></remove>
            <remove statusCode="502" subStatusCode="-1"></remove>
            <remove statusCode="504" subStatusCode="-1"></remove>
            <error statusCode="403" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="404" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="405" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="408" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="500" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="502" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
            <error statusCode="504" path="/php/handlers/http_error_handler.php" responseMode="ExecuteURL"></error>
        </httpErrors>
    </system.webServer>
    <system.web>
        <customErrors mode="On">
            <error statusCode="403" redirect="/php/handlers/http_error_handler.php?status=403"></error>
            <error statusCode="404" redirect="/php/handlers/http_error_handler.php?status=404"></error>
            <error statusCode="405" redirect="/php/handlers/http_error_handler.php?status=405"></error>
            <error statusCode="408" redirect="/php/handlers/http_error_handler.php?status=408"></error>
            <error statusCode="500" redirect="/php/handlers/http_error_handler.php?status=500"></error>
            <error statusCode="502" redirect="/php/handlers/http_error_handler.php?status=502"></error>
            <error statusCode="504" redirect="/php/handlers/http_error_handler.php?status=504"></error>
            </customErrors>
        </system.web>
    </configuration>

replace

<httpErrors>

with

<httpErrors errorMode="Custom">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM