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 installation tutorial of MySQL 5.7.27 is reco...
Let's take a look at the code file structure ...
1. Introduction: I think the changes after mysql8...
1. View the detailed information of all current c...
1. Docker imports local images Sometimes we copy ...
1. Download address: http://dev.mysql.com/downloa...
Sometimes we need to control whether HTML elements...
1. System installation package yum -y install mak...
Those who have played King of Glory should be fam...
Setting up remote access in mysql5.7 is not like ...
This article uses an example to describe how MySQ...
Table of contents Preface Input box component lay...
Table of contents 1. Download 2. Deployment 1.Ngi...
Preface All requests in Tomcat are handled by Ser...
【SQL】SQL paging query summary The need for paging...