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

域名注册

域名注册是指向互联网域名注册机构或注册服务提供商购买并注册一个域名的过程。通过域名注册,一个人或公司可以获得一个唯一的域名,使其可以创建一个网站并将其公开在互联网上。在注册过程中,通常需要提供一些个人或公司信息,如名称、地址和联系方式等。注册成功后,域名将有一个注册期限,注册者需要定期续费以维持其使用权。

Public @ 2023-04-15 13:50:12

HTTPS改造全流程常见Q&;A

改造前(1)   Q:站点是否一定要做HTTPS?A:从网站安全和用户体验上来讲,HTTPS站点更为安全优质,而百度搜索在索引的时候会考虑优先展现用户体验较好的页面;预计在2018年下半年,HTTPS将作为优质特征之一影响搜索排序。如果您的条件允许,百度建议您做HTTPS,以便于网站获取更多流量。(2)   Q:HTTPS改造的优点是什么?A:HTTPS是公

Public @ 2021-04-12 15:35:46

discuz、ecshop、帝国cms部署https(ssl)后会员无法登录

注意,以下教程只针对我司港台虚拟主机或者亚数的云主机香港IP部署SSL后的301跳转1.discuz部署https后台无法登录:discuz采用: $_SERVER[‘HTTPS’] 方式判断,我司虚拟主机不支持同时也不支持$_SERVER['HTTP_HOST'],需使用$_SERVER['HTTP_FROM_HTTPS']进行判断,其他php程序同样适用。sou

Public @ 2018-11-02 15:55:57

更多您感兴趣的搜索

0.587884s