我有一个 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 关注
- 143 浏览
添加回答
举报
0/150
提交
取消