我有一個由 2 個入口點組成的 vue.js 應用程式(2 SPA's)。其中一個是index.html為客戶網站提供服務,另一個是為平臺服務 ( platform.html)
按照 Vue CLI 檔案,我在我的.htacess檔案中使用以下內容
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
這僅適用于我只有 index.html 并且當我輸入myUrl.com/platform它時不會更改到平臺的情況。我已經嘗試了以下但無法使其作業
<IfModule mod_rewrite.c>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^platform(.*)$ platform.html [L]
RewriteRule ^(.*)$ index.html [L]
</IfModule>
</IfModule>
uj5u.com熱心網友回復:
假設任何以 為前綴的 URLplatform都應該發送到platform.html,index.html然后您可以在根.htaccess檔案中執行以下操作:
DirectoryIndex index.html
RewriteEngine On
# Optimisation - prevent rewritten requests for the front-controller being reprocessed
RewriteRule ^index\.html$ - [L]
RewriteRule ^platform\.html$ - [L]
# Prevent static resources being routed through the app
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Any URLs that start "/platform" (whole path segment only) are sent to "/platform.html"
RewriteRule ^platform($|/) platform.html [L]
# All other URLs are sent to "/index.html"
RewriteRule . index.html [L]
RewriteBase此處不需要該指令。
您不需要<IfModule>包裝器,除非這些指令是可選的(它們不是)。(以這種方式嵌套這些包裝器是沒有意義的。)有關此問題的更多討論,請參閱我對網站管理員堆疊上的以下問題的回答:檢查 mod_write 真的有必要嗎?
請注意,對檔案根目錄的請求實際上并未由上述指令重寫,而是index.html由DirectoryIndex指令發送至該指令 - 這通常已在服務器上配置,因此此處可能不需要該指令。
更新:由于您的 URL 類似于/platform/<subroute>,而不是/platform<something>,因此上述規則中的正則運算式會更好^platform($|/),而不是簡單的^platform,以便僅匹配整個路徑段并避免可能匹配太多,例如/platformsomething. (我已經更新了上面的代碼。)
^platform($|/)匹配platform或platform/something,但不匹配platformsomething。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/322374.html
標籤:阿帕奇 Vue.js .htaccess 改写 url重写
下一篇:域名不重定向
