HTTP to HTTPS

Scenario :

You want to force people coming to your site to use HTTPS. Either for the entire site or a small sub-section of it.

Note

Using mod_rewrite to do this isn't the recommended behavior. See RedirectSSL

Fix :

RewriteEngine On
# This will enable the Rewrite capabilities RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

Entire site (.htaccess) :

Note: While the rules you need are the same as above (because the rule above doesn't depend on any of the quirks of rewrite in .htaccess), you will need to ensure that you place this in a .htaccess file in the root of the site you want to apply it against, and to make sure you have the appropriate AllowOverride configuration in your httpd.conf

Specific Directory

Either put the above solution in a .htaccess file in the directory to be affected, or put the URI prefix in the regex itself.

RewriteEngine On
# This will enable the Rewrite capabilities RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS RewriteRule ^/?secure/(.*) https://%{SERVER_NAME}/secure/$1 [R,L]
# This rule will redirect all users who are using any part of /secure/ to the same location but using HTTPS.
# i.e. http://www.example.com/secure/ to https://www.example.com/secure/
# This means if you dont want to force HTTPS for all directories you can force it for a specific sub-section of the site.

Apache RewriteHTTPToHTTPS的更多相关文章

  1. Apache执行Python脚本

    由于经常需要到服务器上执行些命令,有些命令懒得敲,就准备写点脚本直接浏览器调用就好了,比如这样: 因为线上有现成的Apache,就直接放它里面了,当然访问安全要设置,我似乎别的随笔里写了安全问题,这里 ...

  2. Apache Ignite之集群应用测试

    集群发现机制 在Ignite中的集群号称是无中心的,而且支持命令行启动和嵌入应用启动,所以按理说很简单.而且集群有自动发现机制感觉对于懒人开发来说太好了,抱着试一试的心态测试一下吧. 在Apache ...

  3. Apache Ignite高性能分布式网格框架-初探

    Apache Ignite初步认识 今年4月开始倒腾openfire,过程中经历了许多,更学到了许多.特别是在集群方面有了很多的认识,真正开始认识到集群的概念及应用方法. 在openfire中使用的集 ...

  4. Apache 与 php的环境搭建

    Apache和PHP的版本分别为: httpd-2.4.9-win64-VC11.zip php-5.6.9-Win32-VC11-x64.zip 下载地址: php-5.6.9-Win32-VC11 ...

  5. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    学习架构探险,从零开始写Java Web框架时,在学习到springAOP时遇到一个异常: "C:\Program Files\Java\jdk1.7.0_40\bin\java" ...

  6. 【开发软件】 在Mac下配置php开发环境:Apache+php+MySql

    本文地址 原文地址   本文提纲: 1. 启动Apache 2. 运行PHP 3. 配置Mysql 4. 使用PHPMyAdmin 5. 附录   有问题请先 看最后的附录   摘要: 系统OS X ...

  7. Apache Cordova开发Android应用程序——番外篇

    很多天之前就安装了visual studio community 2015,今天闲着么事想试一下Apache Cordova,用它来开发跨平台App.在这之前需要配置N多东西,这里找到了一篇MS官方文 ...

  8. java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE

    Android发出HTTP请求时出现了这个错误: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INST ...

  9. Ubuntu下配置apache开启https

    一.HTTPS简述随着网络的日常,信息安全越来越重要,传统的网站都是http协议明文传输,而HTTPS协议是由SSL+HTTP协议构建的可进行加密传输.身份认证的网络协议,比http协议安全. 那ht ...

随机推荐

  1. IDEA IntelliJ常用设置以及快捷键(转)

    转载自:http://macrochen.iteye.com/blog/1035680 关于字体的设置 IDEA下使用雅黑Consolas混合字体      快捷贱, 快捷贱 , 快捷键贱    In ...

  2. error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用

    MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 Debug ...

  3. 关于回溯与n个数的全排列

    今天要讲的题目是全排列的问题:有1.2.3.....n这样一个数列,要求输出其全排列. 那么,显然,这道题目非常之简单,用一个标志数组变量,标记数字的使用情况,然后根据它挑选数字即可.由于题目很简单, ...

  4. 单元测试 – ASP.NET MVC 4 系列

           在开发可测试软件的过程中,单元测试已成为确保软件质量的一个不可或缺部分.测试驱动开发(Test-Driven Development,TDD)是编写单元测试的一种方法,采用该方法的开发人 ...

  5. mysql总结

    //查询日期之前的差距     select user_name ,    from_unixtime(user_lastlogin_time),now() ,        year(now())- ...

  6. -Three.js开发指南---用three.js创建你的第一个三维场景(第一章)

    本章主要做了下面的工作 1 生成一个简单的场景,该场景的物体只有平面和坐标轴 2 在第一个demo的基础上添加光源和方块物体,并生成阴影 3 在第二个demo的基础上,增加动画,使得方块进行旋转 4 ...

  7. 崽崽帮www.zaizaibang.com精选1

    南京郊外免费旅游景点推荐!不花钱又好玩~ 南艺帅哥手绘的南京,想说不爱你都难! [快乐 你懂的]—太原市育华幼儿园小一班 昆明周边游:那些近在咫尺的梨园 弘雅小学开展一年级新生入学准备期活动 大班的主 ...

  8. AngularJS---表达式

    AngularJS的表达式是放在{{}}里面,用{{ }}符号将一个变量绑定到$scope上. angularJS中的表达式有如下特点: 1.只能在其所属作用域内部 所有的表达式都在其所属的作用域内部 ...

  9. 处理ios webview 更新缓存本地css、js后webview缓存无法更新的问题

    项目中需要使用app本地css.js,并且可以根据服务下发自动更新本地css.js.测试发现只要更新后的css或者js和更新前路径一致,webview加载的还是更新前的css.js.怀疑是webvie ...

  10. DHTMLX-Grid

    DHTMLX - Grid 介绍 dhtmlxGrid是一个灵活的.易于使用的JavaScript网格组件,可以创建DHTML表与丰富的编辑- sensing,固定的多行页眉和页脚,可调整大小的.可拖 ...