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 !~ '^ Www.coolfish.cn $') {rewrite ^ (. *) http://www.coolfish.cn $1 permanent ;}
Apache 301 redirection
Rewriteengine onrewritecond % {http_host} ^ coolfish.cn/[Nc] rewriterule ^ (. *) $ http://www.coolfish.cn/#1 [L, r = 301]
Redirect a domain name without WWW to a domain name with WWW