IIS7 Download the HTTP Rewrite module from Microsoft's official website. After the installation is complete, restart the IIS service. Then open the IIS console and you will find an additional component. Double-click "URL Rewrite" and select "Add Rule" in the right window. Add a blank rule and give the rule a custom name (you can name it as you like). For example, I call it "redirect to HTTPS" and the pattern is (.*). Add a condition and enter {HTTPS} to match the pattern. The pattern is ^OFF$. Then configure the operation. The operation type is: redirect. The redirection URL is: https://{HTTP_HOST}/{R:1}. The redirection type is: permanent 301. After completing the settings, click "Apply" on the right and the URL rewriting is configured. After configuration, the content of the web.config file in the root directory is as follows: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="redirect to HTTPS" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration> Apache http jump to https configuration Modify the .htaccess file and add the following lines to it: RewriteEngine On RewriteBase / RewriteCond %{HTTPS} != on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Another way to write it is: RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L] nginx configuration nginx rewrite method Ideas This should be the easiest method for everyone to think of. All http requests can be rewritten to https through rewrite Configuration server { listen 192.168.1.111:80; server_name test.com; rewrite ^(.*)$ https://$host$1 permanent; } After setting up this virtual host, you can rewrite all requests from http://test.com to https://test.com error code 497 497 - normal request was sent to HTTPS Explanation: When this virtual site only allows https access, nginx will report a 497 error code when accessed with http Use the error_page command to redirect the link with the 497 status code to the domain name https://test.com Configuration
index.html refresh the web page Idea Both of the above methods will consume server resources. Let's use curl to visit baidu.com and see how Baidu achieves the jump from baidu.com to www.baidu.com index.html
nginx virtual host configuration
Postscript All three methods mentioned above can be used to force http requests to jump to https requests based on nginx. You can evaluate the pros and cons or choose according to actual needs. You may also be interested in:
|
<<: Detailed explanation of using javascript to handle common events
1. Download the zip archive version from the offi...
This article introduces 5 ways to solve the 1px b...
Table of contents 1. Core 1. Get the Dom node 2. ...
This article shares with you the solution to the ...
Introducing the Geo module of Nginx The geo direc...
This article compares and summarizes four ways of...
Table of contents Concept Introduction Logical ru...
MySQL full text search Chinese solution Recently,...
This article uses examples to illustrate the prin...
Designers have their own font library, which allo...
The specific upgrade script is as follows: Dynami...
This article uses examples to illustrate the func...
Use CSS to modify the browser scroll bar style ::...
1. What is scaffolding? 1. Vue CLI Vue CLI is a c...
1 CSS style without semicolon ";" 2 Tags...