windows服务器IIS强制http跳转https

windows服务器IIS强制http跳转https

在根目录找到web.config之后直接复制下面的重定向代码进去即可

<?xml version="1.0" encoding="UTF-8"?>
 
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="http redirect to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF[        DISCUZ_CODE_0        ]quot; />
                        <add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

如果您的服务器配置了web.config没有生效
请查看您是否有安装URL重定向工具
如果还没有安装
请传送到微软官网下载安装
https://www.microsoft.com/zh-cn/ … mation.aspx?id=7435

windows服务器Apache环境配置SSL

在apache的配置文件(httpd.conf)中,对以下两句话取消注释注意:第一条加载ssl,第二条引入配置文件

在你的Apache目录中找到\conf\httpd.conf并打开,找到如下两行
# LoadModule ssl_module modules/mod_ssl.so
# Include conf/extra/httpd-ssl.conf
将这两行前面的注释符号 # 去掉。
LoadModule ssl_module modules/mod_ssl.so (如果找不到请确认是否编译过 openssl 插件)
Include conf/extra/httpd-ssl.conf

配置httpd-ssl.conf文件
在你的Apache目录中找到\conf\extra\httpd-ssl.conf
在httpd-ssl.conf文件中最后面添加如下信息,其中域名地址根据自己的实际情况修改。

Listen 443
 
SSLPassPhraseDialog  builtin
 
SSLSessionCache        "shmcb:/Apache24/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
 
<VirtualHost _default_:443>
 
DocumentRoot "E:\web\public"
ServerName www.abc.com:443
ServerAdmin admin@example.com
 
SSLEngine on
 
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
 
SSLCertificateFile "C:\Apache24\cert\www\public.pem"
 
SSLCertificateKeyFile "C:\Apache24\cert\www\214132021230522.key"
 
SSLCertificateChainFile "C:\Apache24\cert\www\chain.pem"
 
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/Apache24/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
 
BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
 
#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog "/Apache24/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"
 
</VirtualHost>

在网站根目录的.htaccess文件中配置跳转
配置http跳转https

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</IfModule>

Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

Nginx 自动跳转到HTTPS Nginx设置http自动跳转https SSL配置

方法一

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

方法二

适用于 80端口和443 配置在同一个 server{}内

if ($server_port = 80) {
      rewrite ^(.*)$ https://$host$1 permanent;
}

其他情况, 站点绑定很多域名,只让某个域名跳转:

set $redirect_https 1;
if ($server_port = 80) {
   set $redirect_https "${redirect_https}2";
}
if ($http_host = 'www.yourdomain.com') {
   set $redirect_https "${redirect_https}3";
}
if ($http_host = 'yourdomain.com') {
   set $redirect_https "${redirect_https}3";
}

if ($redirect_https = "123") {
rewrite ^(.*)$ https://$host$1 permanent;
}

示例

server {
        listen       80;
        server_name  www.getssl.cc;
        rewrite ^ https://$http_host$request_uri? permanent;
}

server {
        listen 443;
        ssl on;
        ssl_certificate /etc/ssl/cacert.pem;
        ssl_certificate_key /etc/ssl/privkey.pem;
        server_name www.yourdomain.com;  

        
        server_tokens off;

        location / {
          
                fastcgi_param   HTTPS               on;
                fastcgi_param   HTTP_SCHEME         https;

        }
        
}

Apache自动跳转到 HTTPS Apache设置http跳转https

Apache自动跳转到 HTTPS Apache设置http跳转https

网站根目录新建 .htaccess

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

站点绑定多个域名,只允许www.example.com 跳转

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

******把网址更改为自己的******

高级用法 (可选)

RewriteEngine on

# 强制HTTPS
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
# 某些页面强制
RewriteCond %{REQUEST_URI} ^something_secure [OR]
RewriteCond %{REQUEST_URI} ^something_else_secure
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# 强制HTTP
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{SERVER_PORT} 443
# 某些页面强制
RewriteCond %{REQUEST_URI} ^something_public [OR]
RewriteCond %{REQUEST_URI} ^something_else_public
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

IIS7 IIS8 设置http自动跳转到HTTPS

IIS7 IIS8 设置http自动跳转到HTTPS

IIS7需要先确认是否安装 “URL 重写” 或者 “URL Rewrite” 模块 , 如果您已经安装可以跳过

“URL重写” 模块下载地址

微软下载地址(64位):http://www.microsoft.com/zh-cn/download/details.aspx?id=7435
微软下载地址(32位):http://www.microsoft.com/zh-cn/download/details.aspx?id=5747

1. 选择站点,  “URL 重写”,如果安装的是英文版的 应该是【Url Rewrite】

2.添加 “ 空白规则”

3.添加规则
名称 : HTTPS
匹配URL 模式: (.*)
添加条件:    条件: {HTTPS}  模式: off

操作类型选择:重定向
重定向URL: https://{HTTP_HOST}/{R:1}

设置301跳转

之后点击保存

当然也可以自己直接编辑网站配置文件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>

windows服务器IIS6 自动跳转到HTTPS配置教程

windows服务器IIS6 自动跳转到HTTPS配置教程

1. IIS6中,站点属性-》目录安全性-》编辑中把“要求安全通道(SSL)”勾选上即可。

2. 打开自己网站根目录, 例如 d:webroot,  在根目录新建一个名为  https.htm 的文件,内容如下:

<html>
 <head><title>Redirecting...</title></head>
 <script language="JavaScript">
 function redirectHttpToHttps()
 {
     var  httpURL= window.location.hostname + window.location.pathname +  window.location.search;
     var httpsURL=  "https://" + httpURL;
     window.location  = httpsURL;
 }
 redirectHttpToHttps();
 </script>
 <body>
 </body>
 </html>


3.IIS6中, 站点属性 -》 自定义错误 -》选择 403.4 -》修改文件路径为  d:/webroot/https.htm