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

IIS 7网站新应用目录重定向配置及500内部服务器错误排查

Fixing IIS 7 URL Redirects & 500 Errors for Your New App Folder

Hey Paul, let's tackle this issue head-on—those 500 errors when setting up redirects are usually due to small misconfigurations, and we’ll get your old URLs pointing to the new app without breaking anyone’s bookmarks.

First: Diagnose the 500 Internal Server Error

Before jumping into fixes, let’s figure out why you’re seeing that 500 error. Common culprits include:

  • Missing URL Rewrite Module: IIS doesn’t natively support the <rewrite> config unless you’ve installed the URL Rewrite module. If you don’t see it in your site’s IIS Features view, grab it via the IIS Web Platform Installer (look for "URL Rewrite" in the list).
  • Invalid XML in web.config: Even a missing closing tag or typo (like a misspelled attribute) will trigger a 500. Double-check your config for syntax errors.
  • File Permissions: Ensure the IIS_IUSRS group has read access to your web.config file—without it, IIS can’t parse the rules.
  • Unrecognized Nodes: If the URL Rewrite module isn’t installed, IIS will throw a 500 when it hits the <rewrite> section in your config.

Correct Redirect Configurations

You have two main options depending on whether you want to keep the old app directory (temporarily) or remove it entirely.

Option 1: Redirect from the Old App Directory (Before Deleting It)

If you still have the old app folder in place, add this web.config to it. This will redirect all traffic from the old app to the new one, preserving any subpaths (e.g., yourdomain.com/oldapp/page1 → yourdomain.com/newapp/page1):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- Redirect all old app traffic to new app with 301 (permanent) -->
        <rule name="Old App to New App Redirect" stopProcessing="true">
          <match url="(.*)" /> <!-- Capture all subpaths after /oldapp/ -->
          <action 
            type="Redirect" 
            url="http://yourdomain.com/newapp/{R:1}" 
            redirectType="Permanent" 
          />
          <!-- Optional: Restrict to your specific domain -->
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" />
          </conditions>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Option 2: Redirect from the Root Web.config (Delete the Old App Folder)

If you want to remove the old app folder entirely, add this rule to your root website’s web.config. This targets any requests to the /oldapp path and sends them to the new app:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- Redirect /oldapp/* to /newapp/* -->
        <rule name="Old Path to New App" stopProcessing="true">
          <match url="^oldapp/(.*)" /> <!-- Match any path starting with /oldapp/ -->
          <action 
            type="Redirect" 
            url="/newapp/{R:1}" 
            redirectType="Permanent" 
          />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Key Notes on the Config:

  • Use redirectType="Permanent" (301 redirect) instead of Temporary (302). This tells browsers and search engines to update their bookmarks/indexes, so users won’t keep hitting the old URL long-term.
  • The {R:1} placeholder preserves any subpath from the old URL—critical if users have bookmarks to specific pages in the old app.
  • stopProcessing="true" ensures IIS doesn’t run any additional rewrite rules after this one, preventing conflicts.

Verify & Test

  1. Check for Syntax Errors: Use an XML validator to scan your web.config—even a tiny typo (like a missing quote) will cause a 500.
  2. Enable Detailed Errors: In IIS Manager, go to your site → Error Pages → Edit Feature Settings → select "Detailed errors". This will show you exactly what’s causing the 500 (e.g., "Module not found" for URL Rewrite).
  3. Test the Redirect: Open a browser (incognito mode to avoid cache) and visit an old URL. You should be redirected to the new app, and your browser’s dev tools (Network tab) will show a 301 status code.

Final Steps

Once the redirects work reliably, you can safely delete the old app directory. Users with bookmarks to the old URLs will automatically be sent to the new app—no broken links!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:09:31