部署https(ssl证书)设置301跳转,将http跳转到https的方法

2020-04-18 16:15:51

server

注意,以下教程针对SSL虚拟主机部署SSL后的301跳转

linux操作系统 apache环境

云服务器:【直接在apache上部署的SSL】在对应站点根目录下新建(通过ftp或登录wdcp管理面板中:站点列表-文管-进入public_html-创建文件)一个文件命名为.htaccess。

1

2

3

4

5

6

7

8

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP:From-Https} !^on$ [NC]

#RewriteCond  %{HTTPS} !^on$ [NC]                        # 非亚数机房用这一行替换上一行规则

RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\. 

RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L]

</IfModule>

虚拟主机:可以通过ftp或登录后进入到主机管理面板-文件管理,进入wwwroot,新建一个文件命名为.htaccess文件,保存即可。

编辑.htaccess文件写入以下规则:

1

2

3

4

5

6

7

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP:From-Https} !^on$ [NC]

RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\. 

RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L]

</IfModule>

 

Nginx环境 

编辑nginx站点配置文件(登录wdcp管理面板中:站点列表-文管-虚拟主机站点文件nginx-对应站点配置文件),添加以下规则

1

2

3

4

5

6

server

{

listen 80;

server_name abc.com;

rewrite ^(.*) https://www.abc.com$1 permanent;           #  abc.com对应修改为您自已的域名   

}

 

 

Windows系统 II7环境

云服务器:【直接在IIS上部署的SSL】在对应站点根目录下新建(通过ftp或登录后直接进入到D:\wwwroot\站点ftp命名目录\wwwroot创建)一个文件命名为web.config并编辑添加以下规则:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

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

<configuration>

 <system.webServer>

        <rewrite>

            <rules>

               <rule name="301" stopProcessing="true">

                    <match url="^(.*)$" ignoreCase="false" />

                    <conditions logicalGrouping="MatchAll">                       

                         <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />  

                         <!-- <add input="{HTTPS}" pattern="^on$" negate="true" /> -->  # 非亚数机房用这一行替换上一行规则

                    </conditions>

                    <action type="Redirect" url="https://www.abc.com/{R:1}" redirectType="Permanent" />      # www.abc.com对应修改为您自已的域名

               </rule>

            </rules>

        </rewrite>

    </system.webServer> 

</configuration>

虚拟主机:可以通过ftp或登录后进入到主机管理面板-文件管理,进入wwwroot,新建一个文件命名为web.config并编辑添加以下规则:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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

<configuration>

 <system.webServer>

        <rewrite>

            <rules>

               <rule name="301" stopProcessing="true">

                    <match url="^(.*)$" ignoreCase="false" />

                    <conditions logicalGrouping="MatchAll">

                        <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" />

                    </conditions>

                    <action type="Redirect" url="https://www.abc.com/{R:1}" redirectType="Permanent" />     # www.abc.com对应修改为您自已的域名

               </rule>

            </rules>

        </rewrite>

    </system.webServer> 

</configuration>

 

Windows系统 II6环境

参考http://www.west.cn/faq/list.asp?unid=650 配置一个Rewrite,编辑该Rewrite的规则文件httpd.conf 添加以下规则。

1

2

3

4

5

6

RewriteEngine On

RewriteCond %{HTTP:From-Https} !^on$ [NC]

#RewriteCond  %{HTTPS} !^on$ [NC]                         # 非亚数机房用这一行替换上一行规则                                  

RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]       # www.abc.com对应修改为您自已的域名

RewriteCond %{HTTP_HOST} !^www\. 

RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L]        # www.abc.com对应修改为您自已的域名

 

tomcat环境

在web.xml最后一行</web-app>代码之前添加如下代码即可

1

2

3

4

5

6

7

8

9

10

<security-constraint>

    <!-- Authorization setting for SSL -->

    <web-resource-collection >

        <web-resource-name >SSL</web-resource-name>

        <url-pattern>/*</url-pattern>

    </web-resource-collection>

    <user-data-constraint>

        <transport-guarantee>CONFIDENTIAL</transport-guarantee>

    </user-data-constraint>

</security-constraint>

 

注: 1、discuz使用301方式强制将http跳转到https后会导致后台uc通信失败。

       2、通过该方式设置跳转后,如无法正常跳转访问,请单独建立站点绑定https域名,仍在原来站点设置跳转规则。

 

请根据操作系统、站点部署数量选择以下相应参考文档,文档仅供参考。

A、windows2008+iis7环境SSL部署https单/多站点

B、linux系统SSL部署https单/多站点

C、windows2003系统SSL单站点部署https

以上内容来源于网络,仅供参考。

mysql php html server windows Excel Word Linux CAD

首页  返回列表

本站所有资料均来自网络,若有侵权请联系本站删除!粤ICP备18142546号