一、实现访问http跳转https访问(http的单向认证)

修改配置文件

# vim   /etc/httpd/conf/httpd.conf

  增加在文件最后

  <IfModule ssl_module>

    SSLRandomSeed  startup  builtin   :执行内建的函数;内键指令

SSLRandomSeed  connect  builtin

  域名跳转

  </IfModule>

  RewriteEngine  on

  RewriteCond  %{SERVER_PORT}  !^443$           

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

    :重写条件,服务端口,不是443则成立

:重写规则 .* 表示后面test任意,R替换,将$1替换为https://%{SERVER_NAME}

  IP跳转

Listen 80

<VirtualHost *:80>

    ServerName web

    DocumentRoot /var/www/html/

  RewriteEngine  on

  RewriteCond  %{SERVER_PORT}  !^443$

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

</VirtualHost>  

 

起服务

# service  httpd  restart

 

客户端测试:访问的http直接跳转为https