我有一個 Laravel 應用程序和一個.htaccess文件,用于將所有請求重定向到 HTTPS。然而,問題是,目前它總是重定向到 index.php 而不是正確的路由。例如:http://example.com/users/teams應該重定向到:https://example.com/users/teams而是重定向到:https://example.com/index.php這是我的當前.htaccess:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase / # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]</IfModule>我一直在嘗試玩弄它并尋找答案,但沒有幫助。Laravel 中沒有設置中間件或任何東西來處理 HTTPS 重定向,因此那里不會有任何沖突。
2 回答

qq_笑_17
TA貢獻1818條經驗 獲得超7個贊
在重寫索引之前放置 https 重定向:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

精慕HU
TA貢獻1845條經驗 獲得超8個贊
只需刪除 index.php 默認路徑重定向代碼:-
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
只需將此代碼放在您的 .htaccess 文件中
- 2 回答
- 0 關注
- 169 瀏覽
添加回答
舉報
0/150
提交
取消