After deploying the certificate on the domestic 高防, it automatically 301 redirects to HTTPS access.

Published: 2021-05-20

Note:

1. Replace the domain in the rules with the actual domain

2. You do not need to enable or deploy HTTPS on the server

3. Do not enable Force HTTPS in BaoTa Panel

Apache environment:

Create a .htaccess file in the website root directory, then write the following rules into it. If the file already exists, add the following rules to it

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]                                      
RewriteCond %{HTTP_HOST} ^(www.)?abc.com$ [NC]                                     # Redirect abc.com and www.abc.com to https://www.abc.com to prevent Apache subsites from being affected by inheriting the parent directory's .htaccess
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
</IfModule>

Nginx environment:

Edit the corresponding site configuration file and add this if condition configuration in the server configuration node

server
{
listen 80;
server_name abc.com;   
}
# Add the following code in the website server configuration section
if ( $http_from_https != 'on' ){
     rewrite ^(.*) https://www.abc.com$1 permanent;           # Replace abc.com with your own domain
 }

Windows systems IIS7 and above:

Create a web.config file in the website root directory and write the following code. If web.config already exists, add the <rewrite>.......</rewrite> rule content after the <system.webServer> configuration node

<?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" />
               </rule>
            </rules>
        </rewrite>
    </system.webServer> 
</configuration>

Windows 2003 system IIS6 environment:

The IIS6 environment requires loading the rewrite.dll component. Add the following rules in httpd.ini or httpd.conf

RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]                                
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]       # Replace www.abc.com with your own domain
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L]        # Replace www.abc.com with your own domain