i would like to get the rule fixed before considering alternative approaches.
I tested the code and I believe the rule functions according your your use case. I used the wildcard pattern. Double check the port and web app name.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Port redirect path" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{R:1}" pattern="WebAppDemo" />
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}:9443/{R:1}/{R:2}" redirectType="Found" />
</rule>
<rule name="Port redirect root" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{R:0}" pattern="WebAppDemo" />
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}:9443/{R:0}" redirectType="Found" />
</rule>
</rules>
</rewrite>
<staticContent>
<clientCache cacheControlMode="NoControl" />
</staticContent>
</system.webServer>
</configuration>
I used the following reference documentation.
Edit: You're configuration is returning 301 (Moved Permanently). Your browser can/will cache the URL. If making rule changes does not seem to changes anything then clear your browser cache.