Search code examples
iisurl-rewriting

IIS - Url Rewrite and subfolers


I'm new to URL Rewrite so any help is appreciated. my current situation is that I have a subdomain set up that is currently being rewritten to point to an internal server (reverse proxy). This works fine and dandy.

The issue is when I try to access subfolders. For example, www.website.com returns the appropriate default document, but www.website.com/subfolder/doc.html still returns the default document from www.website.com

Below is the contents of the web.config file for the site. I made this using the directions from an article on mircrosoft's website.

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

As always, Any help is appreciated. (if it makes any difference this is on an older server running IIS 8)


Solution

  • You can refer to this rule:

    <rule name="test">
      <match url="^(.*)$" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^website.com$" />
        </conditions>
      <action type="rewrite" url="server:8080/{R:1}" />
    </rule>