I have 2 sites with name like https://www.site1.com and https://www.site1abc.com. I am trying to add Rewrite rule for site1.com only.

<rule name="Custom Rule" stopProcessing="true">
    <match url="(.*[^/])$" />
        <add input="{StaticRedirectsPatient:{REQUEST_URI}}" 
             pattern="^(https:\/\/(.*).)?site1.com/(.*)" />
    <action type="Redirect" redirectType="Permanent" url="{C:0}" />

The above is getting applied to site1abc also. How to apply only for site1.com. Is there way to check rule should get applied to site1.com and not to site1abc.com keeping in mind both contain the keyword site1.

1 Answer 1


You can try to use the condition rule from this configuration sample below:

<rule name="www.site1.com" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^(site1\.com|www\.site1\.com)$" />
    <action type="Redirect" redirectType="Permanent" url="{C:0}" />
  • With above we can check for hostname but hostname can be different for different environments. So how to handle that case. So I need condition like if hostname or uri contains site1.com then redirect should work
    – Vikram
    Commented Oct 4, 2022 at 13:45
  • 3
    ... You would define different configs and/or transform your configs per-environment
    – Mark Cassidy
    Commented Oct 4, 2022 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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