I'm having an issue where by if a user gets to a url that isn't supposed to be rewritten and doesn't actualyl exist, I want them to get a 404 error page but the rewrite rules seem to keep taking over.. .. so if a user goes to domain.com/blah/ the rewrite
engine rewrites it to the category.aspx page / rule, but that doesn't actually exist.. same goes go domain.com/blah.aspx etc..
By reference to your rules, non-existing file/folder requests being redirected to catagory.aspx is what expected(due to ruleRewriteUserFriendlyURL2). I would suggest you do an evaluation in code of catagory.aspx. If the catagory name is unknown, redirect
the requests to a 404 error page.
Thanks.
Marked as answer by Lloydz on May 28, 2012 09:06 AM
michaeleaton
1 Post
Rewrite rules taking over 404 error..
May 21, 2012 10:51 AM|LINK
Good Morning guys,
I'm having an issue where by if a user gets to a url that isn't supposed to be rewritten and doesn't actualyl exist, I want them to get a 404 error page but the rewrite rules seem to keep taking over.. .. so if a user goes to domain.com/blah/ the rewrite engine rewrites it to the category.aspx page / rule, but that doesn't actually exist.. same goes go domain.com/blah.aspx etc..
Can anyone help me out?
Rules:
-
<rewrite>
<outboundRules>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)viewProduct\.aspx\?catName=([^=&]+)&(?:amp;)?productName=([^=&]+)$" />
<action type="Rewrite" value="{R:1}{R:2}/{R:3}/" />
</rule>
<rule name="OutboundRewriteUserFriendlyURL2" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)category\.aspx\?catName=([^=&]+)$" />
<action type="Rewrite" value="{R:1}{R:2}/" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<clear />
<rule name="IgnoreSubdirectories" stopProcessing="true">
<match url="^facebookcontent/.*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="None" />
</rule>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^viewProduct\.aspx$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/facebookcontent$" negate="true" />
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^catName=([^=&]+)&productName=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/([^/]+)\.aspx$" />
<conditions logicalGrouping="MatchAny">
</conditions>
<action type="Rewrite" url="viewProduct.aspx?catName={R:1}&productName={R:2}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
<rule name="RedirectUserFriendlyURL2" stopProcessing="true">
<match url="^category\.aspx$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/facebookcontent$" negate="true" />
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^catName=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="false">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="category.aspx?Name={R:1}" />
</rule>
</rules>
</rewrite>
-
Thanks,
Michael
iis7 asp.net url rewrite
Lloydz
2335 Posts
Microsoft
Re: Rewrite rules taking over 404 error..
May 23, 2012 07:14 AM|LINK
Hi Michael,
By reference to your rules, non-existing file/folder requests being redirected to catagory.aspx is what expected(due to ruleRewriteUserFriendlyURL2). I would suggest you do an evaluation in code of catagory.aspx. If the catagory name is unknown, redirect the requests to a 404 error page.
Thanks.