zoukankan      html  css  js  c++  java
  • apache实现http自动转为https

    1.确认此服务器apache已经配置过证书可以用https访问到

    2.确认/etc/apache2/ports.conf 下有

    Listen 80
    Listen 443(此条)

    3.配置虚礼主机定将域名位到指定文件夹

    <VirtualHost *:80>
    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html/laravel/public
            ServerName www.uipxw.com
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    
    <VirtualHost *:443>
    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html/laravel/public
            ServerName www.uipxw.com
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    

      两条记录相同监听端口不同

    4.无框架在需要转为https的入口新建。.htaccess文件

    写入

    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    </IfModule>
    

    5.有框架在需要转为https的入口新建。.htaccess文件

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # BEGIN WordPress
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

      如果不强制转为https框架的(.htaccess文件的内容应该是)

    <IfModule mod_rewrite.c>
      Options +FollowSymlinks -Multiviews
      RewriteEngine On
    
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
    </IfModule>
    

     

  • 相关阅读:
    python之路-day31-守护进程、锁、队列、生产者消费者模型
    python之路-day30-进程
    python之路-day26 初探网络编程
    python之路-day25-包
    python之路-day21-模块介绍1
    python之路-day19-面向对象之约束
    递归格式模板
    java创建一个窗体
    异常throws关键字 异常throw关键字
    多个catch块
  • 原文地址:https://www.cnblogs.com/qqlong/p/8430248.html
Copyright © 2011-2022 走看看