I am having a problem with the URL rewrite module. I have a subdomain with it's own set of rewrite rules and I am getting 404 errors whenever I click on Urls that have been reformatted. My setup is below.
On the main site I am using the following inbound rule to rewrite requests from {http}://mydomain.com/subdomain to {http}://subdomain.mydomain.com.
<rule name="Redirect to Sub Domain" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^subdomain.mydomain.com$" />
<add input="{PATH_INFO}" pattern="^/subdomain/" negate="true" />
</conditions>
<action type="Rewrite" url="/subdomain/{R:0}" logRewrittenUrl="false" />
</rule>
This resolves fine and works fine. All direct links to other pages on the subdomain render fine. For example {http}://subdomain.mydomain.com/Page1.aspx works.
Now, in my subdomain I an using an outbound rule to change the rewritten URLs to remove the subdomain folder from the link.
<rule name="Clean up outbound URLs" preCondition="is text or html">
<match filterByTags="A, Form, Img, Link" pattern="^(?:subdomain|(.*//[_a-zA-Z0-9-\.]*)?/subdomain)(.*)" />
<action type="Rewrite" value="{R:1}{R:2}" />
</rule>
<preConditions>
<preCondition name="is text or html">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
This also works as expected. All links on the pages are rewrittne to remove the subdomain. Links that are written as {http}://subdomain.mydomain.com/subdomain/Page1.apsx are properly changed to {http}://subdomain.mydomain.com/Page1.aspx. These pages will render properly when the link is clicked.
So, this brings me to the problem. I have additional rewrite rules for the subdomain to resolve product pages from product.aspx?pid=123&uid=1 to /products/123/1. Here is one of those rules.
<rule name="Product Details Rewrite Rule" stopProcessing="true">
<match url="^products/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Products.aspx?pid={R:1}&uid={R:2}" appendQueryString="false" />
</rule>
So after the outbound rewrite rule I am left with a url on Page1.aspx that looks like {http}://subdomain.domain.com/products/123/1. This is exactly what I want. The problem is when I click on the link it gives a 404 error with the following details.
-- HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Requested URL: {http}://subdomain.mydomain.com/subdomain/products/123/1
The error leads me to belive that the clicked url was not passed back into the url rewriter and resolved properly. I have FRT turned on but am not getting anything logged when this happens. Can anyone tell me why I am seeing a 404 error and not my products page?