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

‹ Previous Thread|Next Thread ›
  • Domain redirection with subfolder exception

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

    Hello,
    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:

    <rewrite>
                <rules>
                    <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" />
                        </conditions>
                        <action type="Redirect" url="https://dom2.com" appendQueryString="false" />
                    </rule>
                </rules>
            </rewrite>


    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? Find me at https://booktime.xyz/p/lextm
    ---------------------------
    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=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="old.dom1.com" />
                            <add input="{URL}" pattern="^/exception(.*)" negate="true" />
                        </conditions>
                        <action type="Redirect" url="https://dom2.com/{R:0}" />
                    </rule>

    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.

‹ Previous Thread|Next Thread ›