Nginx does not support nested if statements, nor does it allow logical judgment in if statements. The following error will be reported:
When the business requires multiple condition judgments, it can be implemented with the help of intermediate variables For example, our website has multiple subdomains on the PC side, but only one domain name on the mobile side. The corresponding relationship is as follows:
The effect to be achieved: When accessing the PC domain name on the mobile terminal, 301 jump to the corresponding mobile terminal domain name The rewrite rules for nginx are as follows: # Is it a mobile terminal? set $mobile 0; if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) { set $mobile 1; } # Get the subdomain set $prefix 1; if ($host ~* "sub1.test.com") { set $prefix 2; } if ($host ~* "sub2.test.com") { set $prefix 3; } if ($host ~* "sub3.test.com") { set $prefix 4; } set $sign "${mobile}${prefix}"; if ($sign = 11) { rewrite ^(.*) http://m.test.com$1 permanent; } if ($sign = 12) { rewrite ^(.*) http://m.test.com/sub1$1 permanent; } if ($sign = 13) { rewrite ^(.*) http://m.test.com/sub2$1 permanent; } if ($sign = 14) { rewrite ^(.*) http://m.test.com/sub3$1 permanent; } 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. You may also be interested in:
|
<<: MySQL 5.7.18 Green Edition Download and Installation Tutorial
>>: JavaScript to achieve full or reverse selection effect in form
The relationship between Javascript and DOM is ve...
Limit input box to only pure numbers 1、onkeyup = ...
Table of contents 1. Declare and initialize array...
Since I installed the official version of IE8.0, ...
This article shares with you how to use canvas an...
Preface HTTP is a stateless communication protoco...
Project scenario: 1. Upload file restrictions Fun...
When any project develops to a certain complexity...
Table of contents 1. Prototype 2. Prototype point...
XML/HTML CodeCopy content to clipboard < butto...
1. Request answer interface 2. Determine whether ...
Flexible layout (Flexbox) is becoming increasingl...
In a recent problem, there is such a phenomenon: ...
Passing values between mini program pages Good ...
Table of contents Overview Problem Description Ci...