为了账号安全,请及时绑定邮箱和手机立即绑定

htaccess HTTPS 重定向总是重定向到索引

htaccess HTTPS 重定向总是重定向到索引

PHP
慕妹3146593 2021-11-26 15:54:34
我有一个 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>


查看完整回答
反对 回复 2021-11-26
?
精慕HU

TA贡献1845条经验 获得超8个赞

只需删除 index.php 默认路径重定向代码:-


RewriteCond %{HTTPS} !=on

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

只需将此代码放在您的 .htaccess 文件中


查看完整回答
反对 回复 2021-11-26
  • 2 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信