zoukankan      html  css  js  c++  java
  • Apache环境强制跳转到https

    这里用的是集成开发环境XAMPP,假设已经配置好ssl证书,不知如何申请ssl证书者请自行百度。修改Apache相关配置文件,强制所有http跳转到https,假设网站域名为xxx.com。

    1、在httpd-ssl.conf中 <VirtualHost _default_:443>下面增加设置:

    DocumentRoot "D:/web/xxx"
    ServerName xxx.com:443
    ServerAdmin admin@example.com
    ErrorLog "D:/xampp/apache/logs/xxx_https_error.log"
    TransferLog "D:/xampp/apache/logs/xxx_https_access.log"

    2、在httpd-vhosts.conf文件的虚拟域名配置增加以下内容:

    RewriteEngine on
    RewriteCond   %{HTTPS} !=on
    RewriteRule   ^(.*)  https://%{SERVER_NAME}$1 [L,R]

    这样,当输入 www.xxx.com 访问网站时,会自动跳转到 https://www.xxx.com

    广州VI设计公司https://www.houdianzi.com

    完整的<VirtualHost>记录为:

    <VirtualHost *:80>
    	    <Directory "D:/web/xxx">
    	        Options FollowSymLinks Includes ExecCGI
    	        AllowOverride All
    	        Require all granted
    	    </Directory>
    	    ServerAdmin 877040117@qq.com
    	    DocumentRoot "D:/web/xxx"
    	    ServerName www.xxx.com
    
    	    RewriteEngine on
    	    RewriteCond   %{HTTPS} !=on
    	    RewriteRule   ^(.*)  https://%{SERVER_NAME}$1 [L,R]
    	    
    	    ErrorLog "logs/xxx-error.log"
    	    CustomLog "logs/xxx-access.log" common
    </VirtualHost>
  • 相关阅读:
    [ SHOI 2012 ] 随机树
    [ BZOJ 4318 & 3450 / CodeForces 235 B ] OSU!
    [ HNOI 2015 ] 亚瑟王
    [ JSOI 2015 ] Salesman
    [ ZJOI 2007 ] 时态同步
    [ Luogu Contest 10364 ] TG
    [ CodeForces 17 E ] Palisection
    [ BZOJ 2160 ] 拉拉队排练
    Manacher 学习笔记
    [ CodeForces 865 D ] Buy Low Sell High
  • 原文地址:https://www.cnblogs.com/qianxiaox/p/14035586.html
Copyright © 2011-2022 走看看