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

Apache URL重写问题:短URL跳转404(Adobe AEM站点)

Fixing URL Shortening for Adobe AEM (Trimming /en_CA/homepage/ from Paths)

Let's break down what's going wrong with your current setups and fix this step by step. Your goal is to let users access clean short URLs like https://www.example.com/page1.html while ensuring Adobe AEM only receives the full, expected long path (/en_CA/homepage/page1.html)—here's how to make that work:

Why Your Previous Configs Failed

  • First Rewrite Rule Issue: Using the [P] (proxy) flag was incorrect here. This tells Apache to send an external proxy request for the short URL, which doesn't exist, hence the 404. You need an internal rewrite instead of a proxy.
  • AliasMatch Pattern Mistake: Your AliasMatch used ^/[^/]*/(.*), which would match paths like /random/page1.html—not the root-level short URLs you're targeting. The pattern needed to focus on root-level files directly.

Solution 1: Simplified Mod_Rewrite Setup

This is the most straightforward approach. We'll internally rewrite root-level requests to the long AEM path, while avoiding loops by skipping already valid long paths.

Add these rules to your Apache virtual host config (or .htaccess if your server allows it):

# Skip rewrite if we're already dealing with the long AEM path (prevents loops)
RewriteCond %{REQUEST_URI} !^/en_CA/homepage/ [NC]
# Rewrite any root-level request to the corresponding long path
RewriteRule ^/(.*)$ /en_CA/homepage/$1 [L,PT]
  • [L]: Stops Apache from processing any further rewrite rules after this one, avoiding unnecessary work.
  • [PT] (Pass-Through): Ensures the rewritten path is passed to Apache's next processing phase—this is critical for making sure the request reaches AEM's Dispatcher correctly, as it treats the rewritten path as the actual request AEM needs to handle.

Solution 2: AliasMatch + Rewrite Combo (For Granular Control)

If you prefer using Alias for direct path mapping (good for specific file types), adjust your AliasMatch pattern to target root-level files, then add a safety rewrite rule:

# Map root-level .html files to the AEM long path
AliasMatch ^/([^/]+)\.html$ /en_CA/homepage/$1.html

# Optional: Add this if you have root-level folder paths (e.g., /page2/)
AliasMatch ^/([^/]+)/?$ /en_CA/homepage/$1/

# Backup rewrite to catch any other root-level requests
RewriteCond %{REQUEST_URI} !^/en_CA/homepage/ [NC]
RewriteRule ^/(.*)$ /en_CA/homepage/$1 [L,PT]

The corrected AliasMatch pattern ^/([^/]+)\.html$ specifically matches root-level .html files (like /page1.html) and maps them directly to the long AEM path.

Key Checks for AEM Compatibility

  • Dispatcher Allow List: Make sure your AEM Dispatcher's dispatcher.any config includes /en_CA/homepage/ in its allowed paths. If the Dispatcher blocks the long path, the rewrite won't work even if Apache is set up correctly.
  • No External Redirects: We're using internal rewrites (not the [R] flag) so users never see the long URL in their browser—this keeps your public URLs clean while AEM gets the path it expects.
  • Test for Loops: After applying changes, test both short and long URLs to ensure you don't create rewrite loops. You can enable Apache's mod_rewrite logging temporarily to debug any unexpected behavior.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:56:29