I recently wanted to convert a website to https access, but after I had done everything, I went to Baidu Webmaster Platform to authenticate https, but no matter how I submitted it, it kept saying "Please redirect your http site 301 to the https site". I asked questions in the Baidu Webmaster Community, but no one answered, so I had to figure it out on my own. Later I found the reason: Baidu's https authentication strictly abides by 301 redirection. I used IIS6, and the previous code was: RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://%{SERVER_NAME}/$1 [R] Although this writing method can redirect all http to https, it will not pass the Baidu Webmaster Platform. Finally, the code was modified to the following and passed RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] Below I have collected and sorted out the code for setting up 301 redirects after deploying https (ssl) in various website environments. I hope it will be helpful to everyone. Linuxt system Apache environment Cloud server: Create a new file named .htaccess in the root directory of the corresponding site (via FTP or logging in to the wdcp management panel: Site List - Document Management - Enter public_html - Create File). Virtual host: You can enter the host management panel-File Management through FTP or after logging in, enter wwwroot, create a new file named .htaccess file, and save it. Edit the .htaccess file and add the following rules: <IfModule mod_rewrite.c> 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 name RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.abc.com$1 [R=301,L] # Change www.abc.com to your own domain name</IfModule> Nginx Environment Edit the nginx site configuration file (log in to the wdcp management panel: site list-document management-virtual host site file nginx-corresponding site configuration file), add the following rules server { listen 80; server_name abc.com; rewrite ^(.*) https://www.abc.com$1 permanent; # Change abc.com to your own domain name} Windows System II7 Environment Cloud server: Create a new file in the root directory of the corresponding site (via FTP or directly enter D:\wwwroot\site ftp naming directory\wwwroot after logging in) named web.config and edit it to add the following rules: <?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" /> # Change www.abc.com to your own domain name</rule> </rules> </rewrite> </system.webServer> </configuration> Virtual host: You can enter the host management panel-file management through ftp or login, enter wwwroot, create a new file named web.config and edit and add the following rules: <?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" /> # Change www.abc.com to your own domain name</rule> </rules> </rewrite> </system.webServer> </configuration> Windows System II6 Environment Configure a Rewrite, edit the Rewrite rule file httpd.conf or .htaccess and add the following rules. RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301] tomcat environment Add the following code before the last line of </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. When discuz uses the 301 method to force http to jump to https, it will cause the background UC communication to fail. 2. After setting up the redirect in this way, if you cannot redirect normally, please establish a separate site binding https domain name and still set up the jump rules on the original site. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: How to create an index on a join table in MySQL
>>: js canvas realizes slider verification
Port 80 is also configured. First enter the firew...
In my last post I talked about how to make a web p...
A joint index is also called a composite index. F...
MySQL supports nested transactions, but not many ...
Problem Description After installing the plugin E...
Table of contents Importing JavaScript 1. Interna...
Preface: Jenkins' Master-Slave distributed ar...
Heart Attributes opacity: .999 creates a stacking...
Table of contents 1. for loop: basic and simple 2...
This article example shares the specific code of ...
animation Define an animation: /*Set a keyframe t...
Preface The this pointer in JS has always been a ...
There are many special symbols used in mathematic...
Table of contents Why use setState Usage of setSt...
1. Manually create and add my.ini file # CLIENT S...