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
When I was looking at some CSS3 animation source ...
With the development of Internet technology, user...
This article mainly introduces an example of impl...
In many projects, it is necessary to implement th...
Use div to create a mask or simulate a pop-up wind...
Table of contents Implementing HTML Add CSS Imple...
This is the style recommendation given by the W3C ...
1: Download MySql Official website download addre...
Problem Description After installing workstations...
Install Jenkins via Yum 1. Installation # yum sou...
1. Mirror images disappear in 50 and 93 [root@h50...
I usually like to visit the special pages or prod...
Configuration steps 1. Check whether DNS is confi...
There are many scripts on the Internet that use e...
Using the Vue language and element components, we...