Nginx Implementing Domain name redirection with parameter directory Two-level domain name method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.