Ver Fonte

Fix SPA fallback: use extension exclusion instead of %1 capture

%1 backreference was empty (no capture group in prior RewriteConds).
Replace with extension-based exclusion: static file requests (.js,
.css, .png, .woff2, etc.) are skipped by the fallback rule and served
directly via Alias. Only SPA routes without extensions get index.html.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T há 2 semanas atrás
pai
commit
96a20c0323
1 ficheiros alterados com 9 adições e 10 exclusões
  1. 9 10
      deploy/homelegance-chat.conf

+ 9 - 10
deploy/homelegance-chat.conf

@@ -7,7 +7,7 @@
 #   mod_proxy, mod_proxy_http, mod_rewrite, mod_alias
 
 # ── Chatbot API:代理到 Node.js :3000 ────────────────────────────────────────
-# ProxyPass 必须在 Alias 之前声明,否则 Alias 会优先匹配 /chat/api/
+# ProxyPass 必须在 Alias 和 AJP catch-all 之前声明
 ProxyPreserveHost On
 ProxyPass        /chat/api http://127.0.0.1:3000/api
 ProxyPassReverse /chat/api http://127.0.0.1:3000/api
@@ -17,17 +17,16 @@ ProxyPass /chat/ !
 
 # ── Chatbot 静态文件:由 Apache 直接服务 ─────────────────────────────────────
 Alias /chat /redant/web/homelegance-chatbot/dist/public
-<Directory /redant/web/homelegance-chatbot/dist/public>
-    Options -Indexes
+<Directory "/redant/web/homelegance-chatbot/dist/public">
+    Options -Indexes +FollowSymlinks
     AllowOverride None
     Require all granted
 </Directory>
 
-# ── SPA fallback:/chat/* 非文件请求一律返回 index.html ──────────────────────
-# 注意:不能用 %{REQUEST_FILENAME} !-f,Alias 下它检查 DocumentRoot 路径而非 Alias 路径
-# 改用捕获组 $1 拼接真实磁盘路径判断文件是否存在
+# ── SPA fallback:/chat/* 路由请求返回 index.html ─────────────────────────────
+# 用扩展名排除静态文件(不能用 %{REQUEST_FILENAME} !-f,Alias 下路径映射不对)
 RewriteEngine On
-RewriteCond %{REQUEST_URI}                                    ^/chat/
-RewriteCond %{REQUEST_URI}                                   !/chat/api
-RewriteCond /redant/web/homelegance-chatbot/dist/public/%1   !-f
-RewriteRule ^/chat/(.*)$ /redant/web/homelegance-chatbot/dist/public/index.html [L]
+RewriteCond %{REQUEST_URI}  ^/chat/
+RewriteCond %{REQUEST_URI} !/chat/api
+RewriteCond %{REQUEST_URI} !\.(js|css|png|jpg|jpeg|gif|ico|svg|woff2|woff|ttf|eot|map|json|webp|txt)$
+RewriteRule ^ /redant/web/homelegance-chatbot/dist/public/index.html [L]