代码之家  ›  专栏  ›  技术社区  ›  Joe Scotto

.htaccess HTTPS重定向正常,但HTTPS转到/index.php

  •  0
  • Joe Scotto  · 技术社区  · 5 年前

    HTTP 对我的网站的请求总是重定向到 index.php 作为 HTTPS 请求不请求 索引.php 一切正常,工作如期。

    例如:

    https://example.com/contact

    http://example.com/contact 重定向到 https://example.com/index.php 并且没有加载正确的请求页面。

    我的电流 .htaccess 看起来像这样:

    # Always set these headers.
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    
    RewriteEngine On
    # RewriteCond %{SERVER_PORT} 80 
    # RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
    
    # Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]
    
    # Force HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Nico    5 年前

    这是由以下部分引起的:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
    

    http://example.com/contact 变成 http://example.com/index.php 然后你的重写规则强制https重写它 https://example.com/index.php

    我不知道你打算对我引用的部分做什么,但是试着对它进行评论并再次测试。