我有一個 vue-laravel 水療中心。為了讓 vue 應用程式在歷史模式下正常作業,我需要確保它重定向到 index.html。我正在遵循 vue cli 檔案對此的說明,并在 .htaccess 檔案中使用這段代碼
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
同時,我還需要確保所有 http 請求都重定向到 https,我的 hostgator 托管為我提供了這段代碼。
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule ^/?$ "https\:\/\/subdomain\.domain\.com\/" [R=301,L]
問題是這兩段代碼似乎不能一起作業。但是,當另一個被注釋掉時,它們中的每一個都可以作業。
uj5u.com熱心網友回復:
順序很重要。規范(HTTP到HTTPS)重定向需要去之前的重寫來index.html。
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ RewriteRule ^/?$ "https\:\/\/subdomain\.domain\.com\/" [R=301,L]
然而,這條規則被寫入重定向到自身并導致重定向回圈!(這不是 HTTP 到 HTTPS 重定向的一部分。)
您不需要<IfModule>包裝器,也不需要重復RewriteEngine指令。
換句話說:
RewriteEngine On
# Redirect HTTP to HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Front-Controller
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
您實際上并未使用該RewriteBase指令,因此我將其洗掉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/322390.html
標籤:Vue.js .htaccess 单页应用程序 vue-cli
上一篇:使用htaccess將index.php?p=重定向到product.php?id=
下一篇:如何修改char陣列中的字符
