Home > Net >  IIS web.config rewrite - Remove specific subfolder from URL
IIS web.config rewrite - Remove specific subfolder from URL

Time:08-30

How can I remove a specific subdirectory from my URL?

Examples:

www.mysite.com/web/Login ➡️ www.mysite.com/Login
www.mysite.com/web/Admin/Panel ➡️ www.mysite.com/Admin/Panel
www.mysite.com/web/Orders ➡️ www.mysite.com/Orders

I already tried

        <rewrite>
            <rules>
                <rule name="removeWeb" stopProcessing="true">
                    <match url="^web/(.*)" />
                    <action type="Rewrite" url="{R:1}" />
                </rule>
            </rules>
        </rewrite>

but no success.

For context, this is a .NET Framework site being reached by a .NET Core site with YARP proxy.

CodePudding user response:

Clear the cache and try again, if it still doesn't work, you can try the following rule:

<rewrite>
  <rules>
     <rule name="Remove web" stopProcessing="true">
        <match url=".*(web)(. )" />
        <action type="Redirect" url=http://www.mytest.com{R:2} appendQueryString="false" />
     </rule>
  </rules>
</rewrite>

Mysite cannot be used in post, so I use test instead.

  • Related