Redirect a domain name without WWW to a domain name with WWW

Source: Internet
Author: User
Tags to domain

Domain names without WWW and without WWW are not the same thing: the former is called the root domain name, and the latter is the second-level domain name of the former. For a long time, people have become accustomed to bringing WWW when visiting websites. Therefore, most webmasters and friends use the domain name resolution together with or without www. However, for search engines, two domain names will be differentiated. From the SEO perspective, we 'd better direct 301 of domain names without WWW to domain names with www, to prevent weight loss. The following describes the 301 targeting method in nginx and Apache.

301 redirection method in nginx

If ($ http_host !~ '^ $') {rewrite ^ (. *) $1 permanent ;}

Apache 301 redirection

Rewriteengine onrewritecond % {http_host} ^[Nc] rewriterule ^ (. *) $ [L, r = 301]


Redirect a domain name without WWW to a domain name with WWW

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: 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.