How about:
<rule name="Redirects olddomain.com/anyusefuldir" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".+" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?olddomain\.(com|org)$" />
</conditions>
<action type="Redirect" url="https://newdomain.org/{R:0}" />
</rule>
<rule name="Redirects olddomain.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".+" negate="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?olddomain.(com|org)$" />
</conditions>
<action type="Redirect" url="https://newdomain.org/oldsite" />
</rule>
The first rule matches when there is a path; the second matches when you navigate to the root of the site.
And you don't need two conditions; the one pattern will match with or without the
www.
prefix. But you do need to escape the
.
character, as it has special meaning in a regular expression.
URL Rewrite Module Configuration Reference | Microsoft Learn[
^]