简体   繁体   中英

Web.config rewrite root URL but not subfolder

I need a rewrite rule to redirect the root URL for a subfolder to the root of the domain, but I want to allow URLs in the subfolder. In other words:

  • www.domain.com/subfolder redirect to www.domain.com
  • www.domain.com/subfolder/ redirect to www.domain.com
  • www.domain.com/subfolder/page1 this should NOT redirect

Thanks!

Try this:

<configuration>
  <location path="domain.com/subfolder">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://domain.com" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
  <location path="domain.com/subfolder/">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://domain.com" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM