IIS and Apache rewrites and redirects working together

apache-2.2iisredirectrewrite

I'm having some trouble with IIS and apache working on the same server. Specifically, any redirects that apache does don't replace the website domain with the target domain. Here's an example:
Trying to redirect to
https://s3.amazonaws.com/company-documentation/Help/Product/index.html
instead redirects to
https://website.company.com/company-documentation/Help/Product/index.html

I currently have it set up so that IIS redirects any traffic to apache and rewrites the url to hide the non-standard port number. The following are the IIS rewrite rules I have setup and the apache htaccess redirects.

Here's an htaccess root folder redirect rule in apache:

# Turn mod_rewrite on
RewriteEngine On

RewriteRule "^Documentation/Product/(.*)$" "https://s3.amazonaws.com/company-documentation/Help/Product/$1" [L,NC]

This is the IIS web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://website.company.com:8081/{R:1}" />
                    <serverVariables> 
                        <set name="HTTP_ACCEPT_ENCODING" value="" /> 
                    </serverVariables> 
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://website.company.com:8081/(.*)" />
                    <action type="Rewrite" value="http{R:1}://website.company.com/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

The apache htaccess rewrite works fine on the current production server where only apache is installed as a web server. The new server needs to have both IIS and apache on the same server, to serve both the CRM and the website.
Any suggestions on how to make this work?

EDIT: I'm not sure that having the Apache server redirect to IIS for CRM requests will work because the ADFS installed on the server uses ports 80 and 443, which would need to be used to make Apache the default request handler for HTTP and HTTPS request.

Best Answer

The solution is to go the the ARR proxy settings and uncheck “reverse rewrite host in response headers“. Source: https://forums.iis.net/t/1176725.aspx