You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IIS规则中移除子文件夹?站点迁移后规则配置求助

Hey there! Let's sort out that IIS rewrite rule issue you're facing. Since your new site's URL structure mirrors the old one exactly—just without the subfolder1 segment—we can build a targeted rule to fix this properly.

Solution for IIS Rewrite Rule to Remove subfolder1

First off, make sure you have the IIS URL Rewrite Module installed on your server. This is non-negotiable for the rule to work—if it's missing, you can grab it via the Web Platform Installer in IIS Manager.

Next, add or update the <rewrite> section in your new site's root web.config file with this rule:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Remove subfolder1" stopProcessing="true">
          <!-- Match URLs starting with subfolder1/ -->
          <match url="^subfolder1/(.*)$" />
          <!-- Internally route to the part after subfolder1 -->
          <action type="Rewrite" url="{R:1}" />
          
          <!-- Optional: Uncomment below to redirect (updates browser URL to clean version) -->
          <!-- <action type="Redirect" url="{R:1}" redirectType="Permanent" /> -->
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Quick breakdown of how this works:

  • match url="^subfolder1/(.*)$": This regex targets any incoming URL that starts with subfolder1/, capturing everything after that segment into the {R:1} variable.
  • action type="Rewrite": This maps the request internally to the clean URL (no subfolder1) without changing what the user sees in their browser. If you want the address bar to update to the simplified URL (great for SEO), switch to Redirect with redirectType="Permanent" (a 301 redirect).

Troubleshooting if it's still not working:

  • Confirm the URL Rewrite Module is enabled for your specific site in IIS Manager.
  • Ensure your web.config is placed in the root of www.mycoproduct.com, not in a subfolder.
  • Test with a sample URL: If someone visits www.mycoproduct.com/subfolder1/about.html, it should load www.mycoproduct.com/about.html seamlessly.
  • Use the Test Pattern tool in the IIS URL Rewrite module to debug whether your regex is matching URLs correctly.

If you need to cover cases where subfolder1 doesn't have a trailing slash (like www.mycoproduct.com/subfolder1page), adjust the match regex to ^subfolder1(.*)$ instead.

内容的提问来源于stack exchange,提问作者jimmyd40

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:27:55