Selaa lähdekoodia

Fix Apache SPA fallback for Alias + RewriteRule conflict

%{REQUEST_FILENAME} !-f checks against DocumentRoot, not the Alias
path, causing all /chat/assets/*.js requests to match the fallback and
return index.html (0.8kB) instead of the actual JS bundle.

Fix: use capture group $1 to build the real filesystem path for the
file-existence check:
  RewriteCond /redant/web/.../dist/public/%1 !-f
  RewriteRule ^/chat/(.*)$ .../dist/public/index.html [L]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T 2 viikkoa sitten
vanhempi
commit
bc0d946db0
1 muutettua tiedostoa jossa 9 lisäystä ja 4 poistoa
  1. 9 4
      deploy/homelegance-chat.conf

+ 9 - 4
deploy/homelegance-chat.conf

@@ -12,6 +12,9 @@ ProxyPreserveHost On
 ProxyPass        /chat/api http://127.0.0.1:3000/api
 ProxyPassReverse /chat/api http://127.0.0.1:3000/api
 
+# 阻止 /chat/ 被 AJP catch-all 拦截
+ProxyPass /chat/ !
+
 # ── Chatbot 静态文件:由 Apache 直接服务 ─────────────────────────────────────
 Alias /chat /redant/web/homelegance-chatbot/dist/public
 <Directory /redant/web/homelegance-chatbot/dist/public>
@@ -21,8 +24,10 @@ Alias /chat /redant/web/homelegance-chatbot/dist/public
 </Directory>
 
 # ── SPA fallback:/chat/* 非文件请求一律返回 index.html ──────────────────────
+# 注意:不能用 %{REQUEST_FILENAME} !-f,Alias 下它检查 DocumentRoot 路径而非 Alias 路径
+# 改用捕获组 $1 拼接真实磁盘路径判断文件是否存在
 RewriteEngine On
-RewriteCond %{REQUEST_URI}       ^/chat/
-RewriteCond %{REQUEST_URI}      !/chat/api/
-RewriteCond %{REQUEST_FILENAME}  !-f
-RewriteRule ^ /redant/web/homelegance-chatbot/dist/public/index.html [L]
+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]