This article describes the Nginx implementation with the parameter directory domain name redirection two-level domain name method, there is a need to learn friends can refer to.
The following code is a rule based on Nginx subdirectory 301 to another domain name (URL). Functions such as access to http://www.php100.com/phper/php.html (with bars and no bars are different, as can be seen in the code below), automatically 301 to http://php.php100.com
The code is as follows |
Copy Code |
Location ~* ^/phper/{ Rewrite ^/phper/(. *) $ http://php.php100.com/$1 permanent; } |
Test success, OK!
For example: myname.netingcn.com, but the actual access address may be www.netingcn.com/user.php?uid=myname. To enable it to work, first in the DSN parsing there need to configure the pan domain name resolution, then set the Rewrtie in the Nginx configuration file.
The Nginx configuration is as follows:
The code is as follows |
Copy Code |
server { Listen 80; server_name *.netingcn.com; ... if ($host ~* ^ (...). netingcn.com) { Set $sub _name $; Rewrite ^//user.php?uid= $sub _name last; } ... |
This assumes that all 6-character subdomains are user-defined domain names and then rewrite them. In addition, some information in an expression can be stored in a variable by a set instruction, which can then be used
Nginx Implementing Domain name redirection with parameter directory Two-level domain name method