Apache配置http自动重定向到https

相关链接:

Apache支持Vue router使用 HTML5History 模式

Apache配置不带www跳转到带www的域名地址

Apache服务器添加SSL证书(HTTPS)

 

在修改以下配置之前,请先阅读以上文章,开启相应模块支持

方法一、修改httpd.conf

<VirtualHost *:80>
ServerName www.xxx.com                 
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
</VirtualHost>

方法二、修改.htaccess

在.htaccess文件中添加以下代码

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xxx.com/$1 [L,R=301]

 注:www.xxx.com为你的域名

 

posted @ 2022-05-13 17:34  猿了个码  阅读(244)  评论(0编辑  收藏  举报