所以我需要将 HTTP 协议(protocol)重定向到 https,我的 SSL 已经启用并且可以工作,但问题是:每当我输入 HTTP URL 时,我都会被重定向到我网站的 index.php 页面。
这是我的代码:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# add trailing slash to directories and force SSL
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !(/$)
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://example.com/$1/ [R=301,L]
# And for the files
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
最佳答案
根据 Apache2 documentation您可以通过类似的方式简化您的虚拟主机:
<VirtualHost *:80>
ServerName www.example.com
Redirect Permanent/ https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
//ALL Your specifics configurations here
</VirtualHost>
这允许您将端口 80 上的每个请求重定向到 https。 因此,您只需将自己的目录索引配置到 443 的虚拟主机中即可。
希望这对您有所帮助。
关于php - http 重定向到 index.php 而不是 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51473515/