title: Custom 404 page redirect not working in IIS7.5 when missing URL is in a sub-folder
body: <p>I have a site with a mixture of .html and .aspx pages running on a W2K8 R2 server with IIS 7.5.  The site is a redevelopment of an older site and all of the URLs and most of the content has changed from the old site to the new site.  I expect to get a number of 404s as people use old links.</p>
  
  <p>I want to redirect 404 errors to a custom page (/404.aspx).  This is (part) of my web.config:</p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;customErrors mode="On" redirectMode="ResponseRewrite"&gt; 
        &lt;error statusCode="404" redirect="/404.aspx" /&gt;
      &lt;/customErrors&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
        &lt;remove statusCode="404" subStatusCode="-1" /&gt;
        &lt;error statusCode="404" prefixLanguageFilePath="" path="/404.aspx"  
               responseMode="ExecuteURL" /&gt;
      &lt;/httpErrors&gt;
    &lt;/system.webServer&gt;
  </code></pre>
  
  <p>The managed pipeline mode for the App Pool for this site is <code>Integrated</code>.</p>
  
  <p>This redirection to my custom 404.aspx page is working well some of the time, and other times it is only kind of working.   These kind of URLs redirect just fine:</p>
  
  <ul>
  <li><a href="http://www.example.com/no-such-page.aspx" rel="nofollow">http://www.example.com/no-such-page.aspx</a></li>
  <li><a href="http://www.example.com/no-such-page.html" rel="nofollow">http://www.example.com/no-such-page.html</a></li>
  </ul>
  
  <p>However, these kind of URLs (where the missing page is in a sub-folder) get a strange result:</p>
  
  <ul>
  <li><a href="http://www.example.com/folder/not-a-real-page.aspx" rel="nofollow">http://www.example.com/folder/not-a-real-page.aspx</a></li>
  <li><a href="http://www.example.com/folder/not-a-real-page.aspx" rel="nofollow">http://www.example.com/folder/not-a-real-page.aspx</a></li>
  </ul>
  
  <p>What happens with the sub-folder URLs is I get the HTML markup from the 404.aspx page, but the page doesn't render properly because all of the CSS and script references in the page are missing, near as I can tell from sniffing network traffic, because <strong>somehow IIS is trying to insert the <code>/folder/</code> into the URL</strong> for resources with relative paths in my 404.aspx page.  For example, my 404.aspx page, which is in my site's root folder has a reference to <code>css/style.css</code> but for a 404 page triggered by a missing page in /folder/, the browser is trying to download: <code>/folder/css/style.css</code> - which obviously isn't there.</p>
  
  <p><em>Does anyone know what I'm doing wrong here?</em></p>