.htaccess HTTPS重定向工作,但HTTPS转到/index.php

时间:2019-05-12 18:06:59

标签: php apache .htaccess

对我的网站的HTTP请求始终重定向到index.php,因为HTTPS的请求根本不请求index.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]

1 个答案:

答案 0 :(得分:0)

这是由这部分引起的:

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

中将其重写

我不知道您打算如何处理我引用的部分,但请尝试对其进行评论并再次测试。