php - http 重定向到 index.php 而不是 https

标签 php http https url-redirection http-redirect

所以我需要将 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/

相关文章:

http - 获取 Erreur HTTP 403.4 - 配置 IIS 7.0 以使用 SSL 后禁止访问

php - Laravel 数据表不返回 html 链接

php - 为什么要提交以下 PDO 事务?

php - 从批处理文件创建窗口服务?

httpclient postasync windows phone 8.1通用app二次调用404错误

ssl - Istio 服务网格 TLS 配置

.net - ASP.Net https 与 http

php - 本地主机上的子域与 CodeIgniter 下的生产服务器

c++ - 将我简单的 winsock 服务器/客户端应用程序转变为简单的网络服务器

java - Java 中的 HTTPS 以奇怪的结果结束