Categories


Tags


(各种版本) http怎么做自动跳转https?

IIS7以上版本

1. 安装rewrite组件

2. 找到网站根目录web.config文件,替换一下内容(如果没有此文件可以创建一个);

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<system.webServer>

<rewrite>

<rules>

<rule name="HTTP to HTTPS redirect" stopProcessing="true">

<match url="(.*)" />

<conditions>

<add input="{HTTPS}" pattern="off" ignoreCase="true" />

</conditions>

<action type="Redirect" redirectType="Found"

url="https://{HTTP_HOST}/{R:1}" />

</rule>

</rules>

</rewrite>

</system.webServer>

</configuration>

复制代码

3.重启IIS测试访问。

APache 版本

如果需要整站跳转,则在网站的配置文件的<Directory>标签内,键入以下内容:

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$

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

复制代码

如果对某个目录做https强制跳转,则复制以下代码:

RewriteEngine on

RewriteBase /yourfolder

RewriteCond %{SERVER_PORT} !^443$

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

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

复制代码

如果只需要对某个网页进行https跳转,可以使用redirect 301来做跳转!

redirect 301  /你的网页 https://你的主机+网页

Nginx版本

在配置80端口的文件里面,写入以下内容即可。

server {

listen       80;

server_name  localhost;

rewrite ^(.*)$ https://$host$1 permanent;

location / {

root   html;

index  index.html index.htm;

}

复制代码

单独页面通用代码段:以下方法较适合指定某一个子页单独https

在需要强制为https的页面上加入以下代码进行处理http-->https

<script language="JavaScript" type="text/JavaScript">

function redirect()

{

var loc = location.href.split(':');

if(loc[0]=='http')

{

location.href='https:'+loc[1];

}

}

onload=redirect

</script>

复制代码

在需要强制为http的页面上加入以下代码进行处理

https-->http

<script language="JavaScript" type="text/JavaScript">

function redirect()

{

var loc = location.href.split(':');

if(loc[0]=='https')

{

location.href='http:'+loc[1];

}

}

onload=redirect

</script>

复制代码

PHP页面跳转:添加在网站php页面内

if ($_SERVER["HTTPS"] <> "on")

{

$xredir="https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

header("Location: ".$xredir);

}

复制代码

http跳转https的方法较多,以上仅供参考。(本文引用沃通)

来源:景安


Public @ 2013-11-14 15:35:54

使用htaccess绑定域名到子目录

要使用`.htaccess`文件将域名绑定到子目录,您可以按照以下步骤操作: 1. 创建一个名为`.htaccess`的文件。确保该文件位于您想要绑定域名的子目录中。 2. 在`.htaccess`文件中添加以下代码: ```apache RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$ RewriteCon

Public @ 2023-07-29 09:00:18

宝塔面板开启数据库远程登陆权限

此处以开启MySQL权限为例: 1.登陆宝塔面板,找到宝塔数据库管理->MySQL管理; 2.点击右上角MySQL配置文件; 3.在MySQL配置文件中找到bind-address=127.0.0.1,将其更改为bind-address=0.0.0.0; 4.在[mysqld]部分添加skip-name-resolve(在MySQL 5.7.5版本中如果设置了skip-name-res

Public @ 2023-02-25 08:00:18

在IIS下部署SSL证书实现HTTPS

HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版。谷歌已经制定了一项长远的计划,它的最终目标是将所有通过HTTP协议呈现的网页标为“不安全”,对于站长来说,部署SSL证书来迁移到HTTPS是一个现实和重要的问题,那么,对于IIS系统来说,如何部署SSL证书实现HTTPS协议呢?下面就讲述一下具体的实现方法。IIS6对于IIS6来说,支持PFX格式证书,下载包中包含PFX格式证书和密

Public @ 2013-04-08 15:56:00

部署https后访问提存在安全隐患NET::ERR_SSL_OBSOLETE_VERSION

部署https后访问域名出现如下提示:您的连接存在安全隐患此网站使用的安全性配置已过时,这可能会导致您的信息(例如密码、消息或信用卡卡号)在发送至此网站的过程中遭到泄露。NET::ERR_SSL_OBSOLETE_VERSION原因是服务器openssl版本过低,较新版本的浏览器会提示不安全,openssl version -a可查看openssl版本Openssl 1.0.0h支持SSLv2,S

Public @ 2010-10-11 15:55:57

更多您感兴趣的搜索

0.448222s