How to set a rewrite rule to access multiple sites under Default Websites [Answered]RSS

7 replies

Last post Mar 24, 2020 10:18 AM by mavel72

  • How to set a rewrite rule to access multiple sites under Default Websites

    Mar 23, 2020 01:53 PM|mavel72|LINK

    Hi, I have 2 sites under default websites in IIS 8.5 and I want to set a rule to redirect the root site (referti.clinicamaterdei.it) to referti.clinicamaterdei.it/site1

    It works very well, however, if I try to reach referti.clinicamaterdei.it/site2 I get referti.clinicamaterdei.it/site1/site2

    Is there any way to avoid this? I can't put the sites out of default websites unfortunately...

    Thank you very much.

  • Rovastar Rovastar

    5460 Posts

    MVP

    Moderator

    Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 23, 2020 03:09 PM|Rovastar|LINK

    What works well? The rule you have already? Post your existing rule so we can see the issue

    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 23, 2020 03:30 PM|mavel72|LINK

    I set "redirect to this destination" (sorry I'm translating from Italian so I'm not sure it's the right translation) to "https://referti.clinicamaterdei.it/site1"

    So when I write https://referti.clinicamaterdei.it it goes to https://referti.clinicamaterdei.it/site1 and it's quite good.

    But if I write in the url "https://referti.clinicamaterdei.it/site2" i don't get "https://referti.clinicamaterdei.it/site2" but "https://referti.clinicamaterdei.it/site1/site2" instead.

    I hope it's clear enough! Thanks for your answer.

  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 23, 2020 10:31 PM|lextm|LINK

    Lex Li
    IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 24, 2020 02:31 AM|Yuk Ding|LINK

    Hi mavel72,

    Please try this rule. You have to whitelist other application that shouldn't be rewritten <add input="{REQUEST_URI}" pattern="^/(site2|site3|site4|site5)" negate="true" />. If you want to do this dynamically, then you should use httpmodule to get virtual application collection. In IIS URL rewrite we have to do this manually.

                <rules>
                    <rule name="rewrite rule">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="^/(site2|site3|site4)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="site1/{R:1}" />
                    </rule>
                </rules>

    If the reply is helpful, it is appreciated if you could mark it as answer.
    Best Regards,

    Jokies Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 24, 2020 08:55 AM|mavel72|LINK

    Thanks! I'll try later and let you konw about it.

  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 24, 2020 08:56 AM|mavel72|LINK

    I'll take a look, thanks!

  • Re: How to set a rewrite rule to access multiple sites under Default Websites

    Mar 24, 2020 10:18 AM|mavel72|LINK

    Your rule worked perfectly! Thank you very much, I need to study the module deeper.