Configure 301 redirection for www domain names using Nginx

Source: Internet
Author: User


Previously, micro-magic once shared with you many articles on Nginx tutorials (please search by yourself in the search bar on the right of this site using the keyword "Nginx"), about pseudo static, there is a centralized summary of the Nginx pseudo-static articles (transfer) of various programs, but the most common www domain name Jump problems are forgotten. For this jump, SEO is friendly, in micro-Magic's view, I prefer to display my website in the form of www.

# Pseudo-static # Nginx implements 301 redirection for www domain names

1. Redirect example.com to www.example.com

Server {
Listen 80;
Server_name example.com www.example.com;
If ($ host! = 'Www .example.com '){
Rewrite ^/(. *) $ http://www.example.com/#1 permanent;
    }
  }

2. Direct www.example.com to example.com

Server {
Listen 80;
Server_name example.com www.example.com;
If ($ host! = 'Example. Com '){
Rewrite ^/(. *) $ http://example.com/#1 permanent;
    }
  }

3. Not redirect all accesses to the specified page

Server {
Server_naaaaaaame www.aaaaaaa.com;
If ($ host! = 'Aaaaaaa. Com ')
{Rewrite ^/(. *) $ http://www.bbbbbbbbbbb.com/#1 permaaaaaaanent ;}}

If IP address access is used in the first server segment


301 redirection promotes search engine optimization

From the perspective of search engine optimization, 301 redirection is the most feasible method for URL redirection. When the domain name of a website changes, the search engine only indexes the new website and transfers the original external links under the old address to the new one, in this way, the ranking of websites will not be affected by changes in the website. Similarly, when you use the 301 permanent redirection command to direct multiple domain names to the website's primary domain, it does not have any negative impact on website rankings.

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.