madison
madison

Reputation: 93

Why isn't my custom 404 page being redirected to in the case of 404 errors on a ColdFusion site on IIS 7.5? How can I fix it?

Edit: I figured it out a few minutes after posting this question. See my answer below.

This site I'm working on is built with ColdFusion and the web server is IIS 7.5. I have created a custom 404 page, /error.cfm, and I have tried to add code to the web.config file so that when a user gets a 404 error, they're redirected to error.cfm as the custom 404 page. But it's not working at all, it's giving me the default "IIS 7.5 Detailed Error - 404.0 - Not Found" page.

Can someone look at my web.config code and tell me if there's anything wrong with it, or if I can fix this custom 404 page in some way?

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Redirect to WWW" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^example.com$" />
                        </conditions>
                        <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>
            <httpErrors>
                <remove statusCode="404" subStatusCode="-1" />
                <error statusCode="404" path="/error.cfm" responseMode="Redirect" />
            </httpErrors>
            <modules runAllManagedModulesForAllRequests="true"/>
        </system.webServer> 
    </configuration>

As you can see, I have also put in a redirect for all non-www links to www. I'm not sure if this could be interfering with the custom 404 page in any way, but I figured I'd mention it just in case.

Upvotes: 3

Views: 223

Answers (1)

madison
madison

Reputation: 93

I fixed it. I had to go into cpanel, look for "IIS Settings", find "Custom Errors" and set the URL in there. But it didn't work if I put in http://www.example.com/error.cfm, I had to put in http://example.com/error.cfm (without the www).

Upvotes: 2

Related Questions