我不太擅長htaccess并試圖找到我的問題的答案,但到目前為止還沒有運氣。
所以我有這個.htaccess重寫:
RewriteCond %{REQUEST_URI} /(api|nova|nova-api)
RewriteRule .* /index.php
哪個效果很好。
該網站是一個 Angular 網站,其中我有由 JS 路由的動態 URL。
因此,如果我打開基本域:example.com效果很好,因為index.html已提供服務。
但是,如果我打開這樣的路線:example.com/example-route. 它說404。
你能幫我如何修改.htaccess檔案嗎?
uj5u.com熱心網友回復:
RewriteCond %{REQUEST_URI} /(api|nova|nova-api) RewriteRule .* /index.php
您似乎只需要index.html 在API 重寫為index.php. 但是,您應該修改現有規則以添加L標志,并且應該錨定與請求匹配的正則運算式(盡管根本不需要條件RewriteRule,因為應該在指令本身中執行 URL 檢查)。
例如,請嘗試以下操作:
# "index.html" needs to take priority when requesting the root directory
DirectoryIndex index.html
# Abort early if request is already "index.html" or "index.php"
RewriteRule ^index\.(html|php)$ - [L]
# Rewrite certain requests to Laravel API
RewriteRule ^(api|nova|nova-api)($|/) index.php [L]
# Rewrite everything else to Angular
# (unless it already maps to a file or directory)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
由于“主頁”已經正常作業,因此建議DirectoryIndex在服務器配置中已經設定好(并確定優先級index.html),盡管如果這就是所需要的,將其明確設定為index.html(如上)更佳。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/425155.html
