After deploying https(ssl), set up a 301 redirect to redirect http to https.
Published: 2017-03-10
Note: The following tutorial is for the 301 redirect after SSL deployment on our company's virtual hosting or Asia Data Center cloud hosting Hong Kong IP (for non-Asia Data Center computer rooms, please pay attention to replacing the line in the rules); replace the domain in the rules with your own domain.
For WordPress, please refer to:https://www.west.cn/faq/list.asp?unid=2068
Click to view the corresponding rules according to your environment:
2. Virtual hosting Linux system
4. Elastic Cloud Windows system (IIS7)
5. Virtual hosting Windows system
6. Elastic Cloud Windows system (IIS6)
1. Cloud hosting Apache environment
[SSL deployed directly on Apache] Create a new file named .htaccess in the root directory of the corresponding site. Click to view the rules for the Hong Kong Asia Data Center computer room.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{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 .htaccess
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
</IfModule>Cloud hosting Apache environment (Hong Kong Asia Data Center computer room):
<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 .htaccess
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
</IfModule>2. Virtual hosting Linux system
You can use FTP or log in and go to Host Management Panel - File Management, enter wwwroot, create a new file named .htaccess, and save it.
Edit the .htaccess file and write the following rules:
<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 .htaccess
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L]
</IfModule>3. Cloud hosting Nginx environment
Edit the Nginx site configuration file (if it is the wdcp panel, log in to the wdcp management panel: Site List - File Manager - Virtual Host Site File nginx - corresponding site configuration file), and add the following rules. (Click to view the rules for the Hong Kong Asia Data Center computer room)
server
{
listen 80;
server_name abc.com;
rewrite ^(.*) https://www.abc.com$1 permanent; # This is the part to be added; change abc.com to your own domain
}Cloud hosting Nginx environment (Hong Kong Asia Data Center computer room):
server
{
listen 80;
server_name abc.com;
}
# For SSL deployed by CDN in the Asia Data Center computer room, add the following code in the server configuration section of your own website
if ( $http_from_https != 'on' ){
rewrite ^(.*) https://www.abc.com$1 permanent; # Change abc.com to your own domain
}4. Cloud hosting Windows system IIS7 environment
Cloud server: [SSL deployed directly on IIS] Create a new file named web.config in the root directory of the corresponding site (create it via FTP or after logging in directly enter D:\wwwroot\site FTP named directory\wwwroot) and edit it to add the following rules (click to view the rules for deployment by Management Assistant or in the Asia Data Center computer room):
<?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="{HTTPS}" pattern="^on$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.abc.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>Cloud hosting Windows system IIS7 environment (Hong Kong Asia Data Center computer room and servers deployed by Management Assistant)
Note: change it to your own domain
<?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>5. Virtual hosting Windows system
You can use FTP or log in and go to Host Management Panel - File Management, enter wwwroot, create a new file named web.config, edit it to add the following rules, and note to replace it with your own domain.
<?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>6. Cloud hosting Windows system IIS6 environment
Refer to http://www.west.cn/faq/list.asp?unid=650 to configure a Rewrite, edit the rule file httpd.conf of that Rewrite and add the following rules. Click to view the rules for the Hong Kong Asia Data Center computer room
RewriteEngine On
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L] # Change www.abc.com to your own domain
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L] # Change www.abc.com to your own domainCloud hosting Windows system IIS6 environment (Hong Kong Asia Data Center computer room)
RewriteEngine On
RewriteCond %{HTTP:From-Https} !^on$ [NC]
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=301,L] # Change www.abc.com to your own domain
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L] # Change www.abc.com to your own domainTomcat environment (cloud hosting)
Add the following code before the last line </web-app> in web.xml.
<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>
Note: 1. If Discuz uses 301 to force HTTP to HTTPS, it will cause UC communication in the backend to fail.
2. After setting the redirect in this way, if it cannot redirect and be accessed normally, please create a separate site bound to the HTTPS domain, and still set the redirect rules on the original site.
Java virtual hosting for 301 redirect after SSL deployment, refer to: https://www.west.cn/faq/list.asp?unid=1968
Please select the corresponding reference document below according to the operating system and the number of site deployments. The document is for reference only. If you are not familiar with the technology, it is recommended tosubmit a ticket, and our engineers will help you configure it (fees will be incurred).
The above content comes from the Internet and is for reference only.
A. Windows 2008 + IIS7 environment SSL deployment HTTPS single/multiple sites
B. Linux system SSL deployment HTTPS single/multiple sites
C. Windows 2003 system SSL single-site deployment HTTPS
D. Win2012 + IIS8 deploy HTTPS certificate (supports multiple sites)
E. Cloud website builder deploy SSL certificate (HTTPS)
F. Virtual hosting SSL certificate deployment (HTTPS) process
