locked
IIS 7.5 adding 'Document Moved' content when 'Location' header is present RRS feed

  • Question

  • User1554690729 posted

    Hello,

    Using PHP 5.4 and IIS 7.5, I'm trying to develop some REST web services compliant with the HAL specification.

    In this context, when we create an object with a POST request, the expect result is a 201 http response with the Location header targetting the object URL and the JSON of the object created in the content.

    For example the response to my POST request could be :

    Status Code:201 Created
    Location:http://localphp.aufeminin.com/reloaded/manage/admin/api/user/58
    {"id":58,
     "username":"h",
      "_links":{
         "self":{"href":"http:\/\/localphp.aufeminin.com\/reloaded\/manage\/admin\/api\/user\/58"}
      }
    }

    But it seems, that as soon as we have a Location header, IIS adds a 'Document Moved' section to the content.

    For example in this case :

    <head><title>Document déplacé</title></head>
    <body><h1>Objet déplacé</h1>Ce document peut être consulté <a HREF="http://localphp.aufeminin.com/reloaded/manage/admin/api/user/58">ici</a></body>
    {"id":58, "username":...

    How can I disable this behavior of IIS ? How can I avoid the 'Document moved' html content while keeping the Location header ?

    Thanks a lot for your help,

    Laurent Mirguet

    Friday, April 11, 2014 10:13 AM

All replies

  • User212506688 posted

    Hi,

    Try an outbound URL Rewrite rule.

    HTH, Benjamin

    Wednesday, April 16, 2014 9:46 AM
  • User1554690729 posted

    Hello,

    Thanks for your answer but I don't really understand how this would help me.

    I see that an outbound rule can modify on-the-fly the URL provided by the field Location:. But I don't want to change the value of this field, I just want to avoid IIS to add some content to my response.

    Did I miss something in your answer ? Did you mean something else ?

    Thanks for your help,

    Laurent

    Thursday, April 17, 2014 12:21 PM
  • Friday, May 30, 2014 6:38 PM
  • User409000176 posted

    But it seems, that as soon as we have a Location header, IIS adds a 'Document Moved' section to the content.

    Just to confirm, the 201 status response is returned to the client, yes?

    If the correct response status code is coming back, but you just have a problem with the HTML, you might try configuring PHP to go through the ISAPI FastCGI interface, instead of the native CGI handler.  See: http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/configuring-the-fastcgi-extension-for-iis-60 (yes, it says IIS 6.0, but the config will still work on IIS 7+).  You'll need to disable the native FastCGI handler mapping after you've configured the ISAPI FastCGI handler.

    There are some known behavior differences between the ISAPI FastCGI handler, and the native IIS7+ FastCGI handler.  There have been similar reports where the ISAPI one behaves differently in the case of the Location: header.

    Thx!

        --E.

    Monday, June 2, 2014 11:37 AM
  • User-353848062 posted

    DropPhone

    try configuring PHP to go through the ISAPI FastCGI interface



    This can't be the solution [I tried a little, didn't get it to work]. Why does IIS has to add html content and even change the MIME-type? There is just no reason for that. This behaviour breaks so much software.

    ATM I'm trying to get OwnCloud run on my IIS 8.5 machine, but the contacts webinterface is not working because of this bug. It relies on correct HTTP headers with json content appended. The only solution seems to be using a custom location header and a rewrite rule...

    Would be happy for a real fix (stop IIS changing the HTTP answers).

    Tuesday, August 19, 2014 2:51 PM
  • User409000176 posted

    Would be happy for a real fix (stop IIS changing the HTTP answers).

    I'm not entirely sure if I'm allowed to disclose this, but a bug for this issue has been filed & fixed for the next version of Windows (a.k.a. Threshold).

    Thx!

        --E.

    Wednesday, August 20, 2014 11:55 AM
  • User-1993603107 posted

    To circumvent this IIS bug, the following Output Rewrite Rule will check for Status 201, and then eliminate all content lines up to and including the closing body tag:

        <outboundRules>
          <rule name="Remove injected 201 content" preCondition="Status 201">
            <match filterByTags="None" pattern="^(?:.*[\r\n]*)*.*&lt;/body>" />
            <action type="Rewrite" value="" />
          </rule>
          <preConditions>
           <preCondition name="Status 201" patternSyntax="Wildcard">
             <add input="{RESPONSE_STATUS}" pattern="201" ignoreCase="false" />
           </preCondition>
          </preConditions>
        </outboundRules>



    Friday, June 11, 2021 10:33 PM