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

我有一个 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 重定向,因此那里不会有任何冲突。


慕妹3146593
浏览 144回答 2
2回答

qq_笑_17

在重写索引之前放置 https 重定向:<IfModule mod_rewrite.c>&nbsp; &nbsp; <IfModule mod_negotiation.c>&nbsp; &nbsp; &nbsp; &nbsp; Options -MultiViews&nbsp; &nbsp; </IfModule>&nbsp; &nbsp; RewriteEngine On&nbsp; &nbsp; RewriteBase /&nbsp; &nbsp; RewriteCond %{HTTPS} !=on&nbsp; &nbsp; RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]&nbsp; &nbsp; # Handle Front Controller...&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-d&nbsp; &nbsp; RewriteCond %{REQUEST_FILENAME} !-f&nbsp; &nbsp; RewriteRule ^ index.php [L]</IfModule>

精慕HU

只需删除 index.php 默认路径重定向代码:-RewriteCond %{HTTPS} !=onRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]只需将此代码放在您的 .htaccess 文件中
打开App,查看更多内容
随时随地看视频慕课网APP