【问题标题】:htaccess HTTPS redirect always redirecting to indexhtaccess HTTPS 重定向总是重定向到索引
【发布时间】:2019-08-16 10:08:26
【问题描述】:

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

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    只需去掉 index.php 的默认路径重定向代码:-

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

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

    【讨论】:

      【解决方案2】:

      在重写索引之前放置 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 2021-11-10
        • 2012-12-23
        • 2020-07-11
        相关资源
        最近更新 更多