ubuntu 设置http重定向为https

2018-11-30  本文已影响0人  _Net_

1.开启重定向

sudo a2enmod rewrite

2.设置http端口重定向

打开 /etc/apache2/sites-available/000-default.conf ,

在 <\VirtualHost *:80><\VirtualHost> 标签内随便一个地方加入以下三行

RewriteEngine on

RewriteCond  %{HTTPS} !=on

RewriteRule  ^(.*)  https://%{SERVER_NAME}$1 [L,R]

或者在网站目录处新建.htaccess 

    RewriteEngine on

    RewriteBase /

    RewriteCond %{SERVER_PORT} !^443$

    RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

3.最后重启

sudo service apache2 restart

上一篇 下一篇

猜你喜欢

热点阅读