We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Domain redirection with subfolder exceptionRSS

3 replies

Last post Apr 29, 2021 01:26 PM by yousufkhanna76

  • Domain redirection with subfolder exception

    Jul 12, 2020 08:21 AM|lakul83|LINK

    I have a domain old.dom1.com. I want to redirect all contents of this domain to dom2.com, with one exception. The URL old.dom1.com/exception should not be redirected.
    Is this possible and if so how?
    I have already tried this:

                    <rule name="CanonicalHostNameRule" enabled="true" stopProcessing="true">
                        <match url=".*" negate="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}{REQUEST_URI}{URL}" pattern="exception/*" negate="true" />
                        <action type="Redirect" url="https://dom2.com" appendQueryString="false" />

    In principle it works here as well, but e.g. the subfolders like old.dom1.com/example are redirected to dom2.com/example. But all requests, including those to subfolders, should be redirected to dom2.com, but not requests to the subfolder "exception".

    Thanks for your help.

  • Lex Li
    Want to have a chat on the issues you meet? Book an appointment at https://buy.stripe.com/cN24ia0yi7sAdIA7sv
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Domain redirection with subfolder exception

    Jul 13, 2020 02:55 AM|Yuk Ding|LINK

    Hi lakul83,

    Please try this rule. It redirect old.dom1.com/* to dom2.com/* but it won't redirect old.dom1.com/exception

    <rule name="CanonicalHostNameRule" stopProcessing="true">
                        <match url=".*" />
                            <add input="{HTTP_HOST}" pattern="old.dom1.com" />
                            <add input="{URL}" pattern="^/exception(.*)" negate="true" />
                        <action type="Redirect" url="https://dom2.com/{R:0}" />

    Best Regards,
    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Domain redirection with subfolder exception

    Apr 29, 2021 01:26 PM|yousufkhanna76|LINK

    Thanks @Yuk Ding for clearing my ambiguities, 
    The best thing of this forum I have learnt all of things by just reading the threads.