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
When using MySQL, we often sort and query a field...
Table of contents Kill instruction execution prin...
The vue mobile terminal determines the direction ...
Recently, when I was working on a front-end vue.j...
Table of contents Basic Configuration Entry file ...
Tab switching is also a common technology in proj...
In one sentence: Data hijacking (Object.definePro...
Preface: Last Sunday, a senior asked me to help m...
Inside the style tag of the vue component, there ...
Contemporary web visual design has gone through th...
This article shares the specific code of Vue usin...
1. Create an empty directory $ cd /home/xm6f/dev ...
Table of contents Tutorial Series 1. Introduction...
1. What is master-slave replication? Master-slave...
1. Check and install pssh, yum list pssh 2. Becau...