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

redirect from root to subfolderRSS

2 replies

Last post May 14, 2021 01:21 AM by samwu

  • redirect from root to subfolder

    May 13, 2021 07:32 PM|EDSA-CTO|LINK

    We have our Accounting/CRM platform that we need to redirect from the root website to a subfolder. 

    http://company.domain.com redirects to https://company.domain.com/subfolder1

    Our problem we just found in testing using the built-in redirect option in IIS 10 is there is a desktop app and when we click the link to access it from https://company.domain.com/subfolder1 we are getting a 404 error. Upon further examination we determined that the redirect is causing it to go to https://company.domain.com/subfolder1/subfolder2/application.file

    correct address should be https://company.domain.com/subfolder2/application.file

    Application support told me to use URL rewrite. So i have installed the IIS URL rewrite onto the web server.  I followed this guide to setup the redirect from http to https which is working.

    https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https/ 

    What I am stuck on is redirecting from the root website to http://company.domain.com to https://company.domain.com/subfolder1

    Anyhelp would be appreciated. 

  • Re: redirect from root to subfolder

    May 13, 2021 09:28 PM|EDSA-CTO|LINK

    I finally got it to work. I setup 2 rules like so to get it to redirect all http to https requests and go from the root to the subfolder. 

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <httpRedirect enabled="false" destination="" />
            <rewrite>
                <rules>
                    <clear />
                    <rule name="Redirect to Https" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
                    </rule>
                    <rule name="Root to Subdirectory" stopProcessing="true">
                        <match url="^$" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                        <action type="Redirect" url="/subfolder1" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

  • Re: redirect from root to subfolder

    May 14, 2021 01:21 AM|samwu|LINK

    Hi EDSA-CTO,

    I'm so glad that the problem has been resolved. It is so appreciated if you can mark your solution as answer.

    Best regards,

    Sam

    IIS.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. Learn more >