0
votes

URL Rewrite rule for a specific domain

if url is https and have this domain only

https://myServer/SomeApplication/

Redirect it to

https://myServer.mycompany.com/SomeApplication/

Added below didn't work in iis 10, windows server 2019

    <rule name="httpsRedirect2" enabled="true" stopProcessing="true">
                    <match url="^myServer/(.*)" ignoreCase="true"/>                          
                        <action type="Redirect" url="https://myServer.mycompany.com/SomeApplication/" appendQueryString="false" />
    </rule>

Can someone explain what I've done wrong?

1

1 Answers

0
votes

The Rule pattern only can get the URL string as an input, does not include the query string, thus it will not work properly.
Here is an official explanation of how certain parts of the URL string can be accessed from a rewrite rule.
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
We can match the hostname in the Rule Condition section then apply the Rule Action.

        <rule name="Myrule2" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="localhost" />
            </conditions>
            <action type="Redirect" url="https://vabqia969vm/" />
        </rule>
    </rules>
</rewrite>

Feel free to let me know if the problem still exists.