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

Conditional URL rewrite配置问题:多目录无法正确映射至对应dist目录

Fixing the Rewrite Rule Conflict for /app and /staging Prefixes

Looks like your current rewrite rules aren’t distinguishing between the /app and /staging prefixes, which is why requests to example.com/staging are being routed to /app/dist/ instead of their own dist folder. Here’s how to fix this:

Corrected Apache Rewrite Configuration

RewriteEngine On

# Handle requests to /staging (route to staging/dist)
RewriteRule ^staging/$ /staging/dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/staging/dist/
RewriteRule ^staging/(.*)$ /staging/dist/$1 [L]

# Handle requests to /app (route to app/dist)
RewriteRule ^app/$ /app/dist/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/app/dist/
RewriteRule ^app/(.*)$ /app/dist/$1 [L]

# Optional: Keep root URL pointing to app/dist if needed
# RewriteRule ^$ /app/dist/ [L]

Why Your Original Rules Failed

Your original configuration had a broad final rewrite rule (^(.*)$) that matched all requests not pointing to an existing file/directory and not starting with /dist/. When someone visited example.com/staging, since /staging isn’t a file or directory, the rule captured staging as $1 and routed it to /app/dist/staging—that’s why you saw the wrong content.

By splitting the rules into separate blocks for /staging and /app, we:

  • Target only requests starting with each specific prefix
  • Use the [L] flag to stop processing further rules once a match is found
  • Exclude requests already pointing to the respective dist folders to prevent infinite loops

If you need the root URL (example.com/) to still point to /app/dist/, uncomment the optional root rule at the bottom—just make sure it comes after the staging/app rules so it doesn’t override them.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:04:26