欢迎来到源码交易网,为站长提供交易担保服务 访问移动版
站长交易首选担保平台!
酷客淘

百度https认证提示"请将您的http站点301重定向到https站点"的解决办法

日期: 2019-07-01 08:23:18 人气: -


最近想把一个网站改造成https访问,但是一些都做好了,去百度站长平台认证https,结果怎么提交都是出现“请将您的http站点301重定向到https站点”,在百度站长社区提问也没有人回答,最后只能自己摸索。后面找到了原因:原来百度的https认证是严格遵守301重定向的,我用的是iis6,之前的代码为:


RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$  

RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]  


这种写法虽然能够实现将http全部跳转到https,但是在百度站长平台是通不过的。最后将代码修改为以下后便通过了


RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$

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


下面我搜集整理了各种网站环境的部署https(ssl)后设置301跳转的代码,希望能够对大家有所帮助。


linuxt系统 apache环境


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


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


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


1

<span style="color:#696969;"><span style="font-size:14px;"><IfModule mod_rewrite.c>

2

RewriteEngine On

3

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

4

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

5

RewriteCond %{HTTP_HOST} !^www\. 

6

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

7

</IfModule></span></span>

 


Nginx环境 


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


1

<span style="color:#696969;"><span style="font-size:14px;">server

2

{

3

listen 80;

4

server_name abc.com;

5

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

6

}</span></span>

 


Windows系统 II7环境


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


01

<span style="color:#696969;"><span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>

02

<configuration>

03

 <system.webServer>

04

        <rewrite>

05

            <rules>

06

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

07

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

08

                    <conditions logicalGrouping="MatchAll">

09

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

10

                    </conditions>

11

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

12

               </rule>

13

            </rules>

14

        </rewrite>

15

    </system.webServer> 

16

</configuration></span></span>

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


01

<span style="color:#696969;"><span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?>

02

<configuration>

03

 <system.webServer>

04

        <rewrite>

05

            <rules>

06

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

07

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

08

                    <conditions logicalGrouping="MatchAll">

09

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

10

                    </conditions>

11

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

12

               </rule>

13

            </rules>

14

        </rewrite>

15

    </system.webServer> 

16

</configuration></span></span>

 


Windows系统 II6环境


 配置一个Rewrite,编辑该Rewrite的规则文件httpd.conf或者.htaccess 添加以下规则。


1

 

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$

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

tomcat环境


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


01

<span style="color:#696969;"><span style="font-size:14px;"><security-constraint>

02

    <!-- Authorization setting for SSL -->

03

    <web-resource-collection >

04

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

05

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

06

    </web-resource-collection>

07

    <user-data-constraint>

08

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

09

    </user-data-constraint>

10

</security-constraint></span></span>

 


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


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