php - http 重定向到 index.php 而不是 https
问题描述
所以我需要将 HTTP 协议重定向到 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文档,您可以通过以下方式简化虚拟主机:
<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的虚拟主机中。
希望这有帮助。
推荐阅读
- linux - 如何在服务器上提交更改并从代码存储库中提取更新而不会发生冲突?
- javascript - Jinja功能不断更新
- sdk - Flutter 光栅崩溃:FontStyle::registerLanguageList 中的 recursive_mutex 解锁崩溃
- zigbee - 使用 USRP Source 检测 Telosb 排放
- python - 如何使用 open cv 在窗口中打印消息
- c# - 如何模拟(MOQ)已密封设置 AbstractAcquireTokenParameterBuilder 的 IConfidentialClientApplication?
- git - Git 偏移 PowerShell 中的文本
- vb.net - 从 Sharepoint 下载空白和 0KB 的文件
- amazon-web-services - 我如何在 aws _route_table 中做动态路由?
- php - 如何根据 Laravel 中的选定选项在 mysql 数据库的文本框中显示数据