3

We recently replaced most of our default pages from default.htm to default.asp.

Rewrite rules work fine if it's a sub-folder, e.g. example.com/help/default.asp where the default.htm was deleted. If I type domain.com/help/default.htm, it correctly shows the new .asp page and no 404 because the default.htm no longer exists.

At the root entering example.com/default.htm does not redirect to default.asp instead sending the user to the 404 page we created.

Tried exact match vs. wildcard, no difference.

Why the 404 and no redirect?

<rule name="homepage" patternSyntax="Wildcard" stopProcessing="true">
<match url="*example.com/default.htm" ignoreCase="true" />
<action type="Redirect" url="http://www.example.com/default.asp" redirectType="Permanent" />
</rule>

UPDATE: This works on a subfolder redirect from htm to asp:

<rule name="downloadhome" patternSyntax="Wildcard" stopProcessing="true">
<match url="*download/default.htm" ignoreCase="true" />
<action type="Redirect" url="/download/default.asp" redirectType="Permanent" />
</rule>
  • 1
    What rule were you using to match your subfolders? – MrWhite Feb 26 at 18:51
  • This works on a subfolder redirect from htm to asp: – SKidd Feb 27 at 9:43
  • 1
    <rule name="downloadhome" patternSyntax="Wildcard" stopProcessing="true"> <match url="*download/default.htm" ignoreCase="true" /> <action type="Redirect" url="/download/default.asp" redirectType="Permanent" /> </rule> – SKidd Feb 27 at 9:46
1
<match url="*example.com/default.htm" ignoreCase="true" />

I think the url attribute matches against the URL-path only, not the hostname. So the above should read:

<match url="^default\.htm" ignoreCase="true" />

This matches "default.htm" in the document root, or use the pattern default\.htm to match "default.htm" anywhere.

This uses patternSyntax="ECMAScript" on the <rule> (to use regular expressions). Or just remove the patternSyntax attribute entirely, since this is the default option


To have just one rule for both scenarios: a request for the document root and a subdirectory then you could probably do something like the following instead:

<rule name="replacedefaulthtm" stopProcessing="true">
<match url="(.*)default\.htm$" ignoreCase="true" />
<action type="Redirect" url="http://www.example.com/{R:1}default.asp" redirectType="Permanent" />
</rule>

Where {R:1} is a backreference to the captured subpattern (.*) in the preceding rule.

  • That worked with one change as follows: <rule name="replacedefaulthtm" stopProcessing="true"><match url="(.*)default.htm$" ignoreCase="true" /> <action type="Redirect" url="{R:1}default.asp" redirectType="Permanent" />redirectType="Permanent" /> </rule>` – SKidd Feb 27 at 11:10
  • Glad that resolved your problem. Are you saying that using an absolute URL (ie. url="http://www.example.com/{R:1}default.asp") did not work at all or resulted in a malformed redirect or something? Minor fix to the above regex: the second dot in (.*)default.htm$ should strictly be backslash-escaped, so should read (.*)default\.htm$ (I've updated my answer). – MrWhite Feb 27 at 11:25
  • I tested with the absolute URL and no redirect, but using the (.*)default.htm$ did the trick. No idea why but it did the job. – SKidd Feb 28 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.