3

I've just migrated from IIS6 svr2003 to IIS7.5 server 2008r2 and installed the url rewrite. That all works great. The website in question is large and running under .net 2 integrated pipeline. Can't redo in .net 4 at this time. I'm brand new to this and a bit out of my depth here. I'd really like to use the rewrite functionality, but I need the sub-app to work also. Any help would be appreciated.

But, a sub virtual app from an outside vendor has a problem with the rewrite section of the webconfig. I comment it out and the sub virtual works great. I've looked on the web and tried a few things:

<location path="." inheritInChildApplications="false">

or

<location path="." allowOverride="true" />

wrapped around the rewrite module give me: The system.web element has invalid child element location.

I tried right under the system.web in the sub virtual app's webconfig but even with the rewrite commented out - this gives an error. I could try the remove, but wondered if someone could give me some insight on this problem.

Here's the basic rewrite:

<rewrite>
  <rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
      <match url="^sethsBrochure.pdf$" />
      <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      </conditions>
      <action type="Redirect" url="path/path/doc.pdf" appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
      <match url="^sethsBrochure$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="path/path/doc.pdf" />
    </rule>
  </rules>
  <outboundRules>
    <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
      <match filterByTags="A, Form, Img" pattern="^(.*)path/path/doc\.pdf$" />
      <action type="Rewrite" value="{R:1}/ path/path/doc" />
    </rule>
    <preConditions>
      <preCondition name="ResponseIsHtml1">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>
Moshe Katz
  • 15,992
  • 7
  • 69
  • 116

1 Answers1

0

The simplest way is, as you guessed, to use clear or remove in the sub application. For example:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <!-- Insert rules for this application (if any) **below** the "clear" -->
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

However, as you found online, you can also do this using a location block. The problem with what you tried is that the location block needs to be outside the system.webServer block, not inside it.

You write that you tried:

<configuration>
    <system.webServer>
        <location path="." inheritInChildApplications="false">
            <rewrite>
            ...
            </rewrite>
        </location>
    <system.webServer>
<configuration>

Instead, you need to do this:

<configuration>
    <location path="." inheritInChildApplications="false">
        <system.webServer>
            <rewrite>
            ...
            </rewrite>
        <system.webServer>
    </location>
<configuration>
Moshe Katz
  • 15,992
  • 7
  • 69
  • 116