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

Redirecting subdomain to internal server [Answered]RSS

3 replies

Last post Feb 04, 2020 04:48 AM by Jalpa Panchal

  • Redirecting subdomain to internal server

    Feb 03, 2020 02:25 AM|Legacy777|LINK

    I've been searching and trying to get this working for the past couple hours and can't seem to find the right combination to make everything come together.  What I'm trying to do is rewrite https://sub1.domain.com to an internal server https://sub1.internal.com:442 as well as rewrite http://sub1.domain.com to http://sub1.internal.com.  I don't know if this can be accomplished in one rule or if I need two rules.

    I also have other sub domains (sub2, sub3, etc.) that are being served via this IIS server and I don't want to redirect them to the internal server.  This is kind of where I'm getting stuck as all traffic is trying to route to the internal server and it's only working for the https, which is why I think I might need two separate rules.

    Any help is greatly appreciated!

    Thanks

    Josh

  • Re: Redirecting subdomain to internal server

    Feb 04, 2020 02:56 AM|Jalpa Panchal|LINK

    Hi,

    You need to use two rules to implement your requirement. (if your destination URL is different)

    <rule name="http to http internal server" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
                            <add input="{HTTPS}" pattern="off" />
                        </conditions>
                        <action type="Redirect" url="http://www.sample2.com/" />
                    </rule>

    this rule will redirect http URL to http.(you could use rewrite if you want)

     <rule name="https to https" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
                            <add input="{HTTPS}" pattern="on" />
                        </conditions>
                        <action type="Redirect" url="https://www.sample2.com/" />
                    </rule>

    or you could use this below single url rewrite rule:(below rule will not add the :442 in url)

    <rule name="rule1" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
                            <add input="{CACHE_URL}" pattern="^(https?)://" />
                        </conditions>
                        <action type="Redirect" url="{C:1}://www.sample2.com/{R:1}" />
                    </rule>

    Regards,

    Jalpa

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: Redirecting subdomain to internal server

    Feb 04, 2020 04:44 AM|Legacy777|LINK

    Thank you very much for the reply!

    I may have not been clear in my original post, but the server I wanted to redirect to is in my internal network so I had to use rewrite instead of redirect.  I used your code and looked at the reverse proxy wizard code and came up with the following code which seems to work perfectly!

    Does this look ok, or is there anything that could be done differently/better?

    Thanks again for the help!  I really appreciate it.

    Josh

    <rule name="HTTP Redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
            <add input="{HTTPS}" pattern="off" />
        </conditions>
        <action type="Rewrite" url="http://sub.internal.local/{R:1}" />
    </rule>
    <rule name="HTTPS Redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
            <add input="{HTTPS}" pattern="on" />
        </conditions>
        <action type="Rewrite" url="https://sub.internal.local:442/{R:1}" />
    </rule>

  • Re: Redirecting subdomain to internal server

    Feb 04, 2020 04:48 AM|Jalpa Panchal|LINK

    yes. the above-suggested code in my post is just an example you could modify based on your requirement.

    if the post helps to resolve your issue I request you to mark the post as an answer it will help other people who face similar issues. 

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.