title: Default content being added to 301 headers with PHP 5.3.5 / IIS7
body: <p>On <a href="http://www.hesa.ac.uk" rel="nofollow">http://www.hesa.ac.uk</a>, we are using a custom 404 handling script to redirect users from, for exmaple, <a href="http://www.hesa.ac.uk/press" rel="nofollow">http://www.hesa.ac.uk/press</a> to the actual URL, which is an ugly CMS one: <a href="http://www.hesa.ac.uk/index.php?option=com_content&amp;task=category&amp;sectionid=1&amp;id=1&amp;Itemid=161" rel="nofollow">http://www.hesa.ac.uk/index.php?option=com_content&amp;task=category&amp;sectionid=1&amp;id=1&amp;Itemid=161</a></p>
  
  <p>We're running fast-cgi.</p>
  
  <p>A 301 header is sent, then a location header.</p>
  
  <p>It works fine for 99% of our users but some of them are reporting 5 to 6 second loading times. This is, we think, due to a bit of stray content which is turning up in the redirection: </p>
  
  <pre><code>&lt;head&gt;&lt;title&gt;Document Moved&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;&lt;h1&gt;Object Moved&lt;/h1&gt;This document may be found &lt;a HREF="http://www.hesa.ac.uk/index.php?option=com_content&amp;amp;task=category&amp;amp;sectionid=1&amp;amp;id=1&amp;amp;Itemid=161"&gt;here&lt;/a&gt;&lt;/body&gt;
  </code></pre>
  
  <p>This isn't output anywhere in the code that we can see.  Here's the method which actually does the redirection:</p>
  
  <pre><code>    /**
   * Do the actual redirection to the win URL
   *
   */
  function doRedirection() {
  
  
          //start output buffering to trap any content that is output by default by the headers
          @ob_start();
  
          //permanently moved header
          //header( 'HTTP/1.1 301 Moved Permanently' );
  
          //fast-cgi, so use this:        
          header('Status: 301 Moved Permanently', true);              
  
          @ob_end_clean(); // clear output buffer
  
          //location header
          header( "Location: ". $this-&gt;winUrl );  
  
          @ob_end_clean(); // clear output buffer
  
          die();
  
  
  
  }
  </code></pre>
  
  <p>I cannot seem to find any resource which indicates how to stop this extra bit of content being output.  I have tried various variations on the method above to do the redirection.</p>
  
  <p>Has anyone had a similar problem? Does anyone have any ideas?</p>
  
  <p>Cheers,</p>
  
  <p>G</p>
  
  <p>EDIT: we've become aware that this is expected behaviour for IIs7, but IIS6 never used to do it with the same code, and whether it's expected or not, our users are complaining and this seems to be the issue.</p>
  
  <p>EDIT 2: it seems that the only workable solution is to abandon this approach and instead move to IIS7's url rewriting functionality, which entails writing a C# class which clones the functionality of the PHP class then plugging that into IIS.</p>
  
  <p>EDIT 3: HOWEVER, setting a content-length: 0 header might possibly help. Not tested yet though.</p>