Nginx 301 Redirect Jump method in Linux

Source: Internet
Author: User

The first case: access to the AAAAAAA station directed to the BBBBBBBBBBB station

The code is as follows Copy Code
server {
Server_naaaaaaame www.aaaaaaa.com;
rewrite ^ (. *) http://www.bbbbbbbbbbb.com$1 permaaaaaaanent;
•}

In the second case: not all redirects to the AAAAAAA station are redirected to the specified page

The code is as follows Copy Code
server {
Server_naaaaaaame www.aaaaaaa.com;
if ($host!= ' aaaaaaa.com ')
{rewrite ^/(. *) $ http://www.bbbbbbbbbbb.com/$1 permaaaaaaanent;}

will also be redirected if write is used for IP access in the first server segment

A third type of jump with www or without www

The code is as follows Copy Code

Server
•{
Server_naaaaaaame c.net
rewrite ^/(. *) $ http://www.c.net/$1 permaaaaaaanent;
•}


The following is a nginx rule jump:

First, in your domain name management inside the definition of c.com and www.c.com point to your host IP address, we can use the nslookup command test: Direct input nslookup c.com and Nslookup have a record point to IP.

Second, we can configure rewrite rules within the nginx. Open nginx.conf File
Find your server configuration segment: "The following is my server configuration segment"

The code is as follows Copy Code
Server
{
Listen 80;
server_name www.c.com c.com;
if ($host!= ' www.c.com ') {
Rewrite ^/(. *) $ http://www.c.com/$1 permanent;
}

This is the user directly access c.com direct jump www.c.com. That is, let the domain name without www jump to the domain name with www.

Third, we can be more than two domain names, three-level domain name can jump at will, or let them all jump to blog.c.com this domain name
Agree to add the following statement:

  code is as follows copy code
server
{
Listen 80;
server_name blog.c.com wgkgood.gicp.net;
if ($host = ' wgkgood.gicp.net ') {
rewrite ^/(. *) $ http://blog.c.com/$1 permanent;
}

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.