部署https(ssl)后设置301跳转将http跳转到https

linux系统 apache环境

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
#RewriteCond  %{HTTPS} !^on$ [NC]                      # 非亚数机房用这一行替换上一行规则
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC]                # 将abc.com和www.abc.com跳转到https://www.abc.com,防止apache子站继承上级目录.htaccess受影响
RewriteRule ^(.*)$ https://www.njsc.cc/$1 [R=301,L]
</IfModule>

虚拟主机

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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC]                # 将abc.com和www.abc.com跳转到https://www.abc.com,防止apache子站继承上级目录.htaccess受影响
RewriteRule ^(.*)$ https://www.njsc.cc/$1 [R=301,L]
</IfModule>

Nginx环境

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

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

亚数机房CDN部署的SSL添加下面代码

if ( $http_from_https != 'on' ){
     rewrite ^(.*) https://www.njsc.cc$1 permanent;           #  njsc.cc对应修改为您自已的域名
 }

Windows系统 II7环境

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

<?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.njsc.cc/{R:1}" redirectType="Permanent" />      # www.njsc.cc对应修改为您自已的域名
               </rule>
            </rules>
        </rewrite>
    </system.webServer> 
</configuration>

虚拟主机

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

<?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.njsc.cc/{R:1}" redirectType="Permanent" />     # www.njsc.cc对应修改为您自已的域名
               </rule>
            </rules>
        </rewrite>
    </system.webServer> 
</configuration>

原文链接:http://www.njsc.cc/778.html,转载请注明出处。

0

评论0

请先

站内资源收集于互联网,若侵犯了您的合法权益,请联系我们删除!
没有账号? 注册  忘记密码?