Apache 设定 http 自动转址导向 https


当网站从 http 转换到 https 后,想自动将前往 http 的访客自动转址到 https,可以通过修改 .htaccess 设定mod_rewrite,或者直接编译 httpd.conf 实现,以下是两种方法的设定步骤。

.htaccess
例如我想将所有访客重新导向 https 相应的页面,只要在 .htaccess 设定即可:

修改后便会生效,不用重新启动 Apache.

httpd.conf
在 httpd.conf 找到 http 的相关 virtualhost, 在段落最后加上以下一行:

Redirect permanent / https://www.phpini.com

修改后需要重新启动 Apache 才会生效:

# systemctl restart httpd
Tags:

One Response

  1. 过客 28 June 2017

Leave a Reply