做SEO时需要正确处理带www和不带www域名的关系:
1、我们讲过URL标准化的概念,在搜索引擎看来,带www和不带www的URL是不同的两个URL,当它们指向同一个网站时,会让搜索引擎不懂应该选择哪一个URL作为主要的。所以,我们建议部分符合条件的主机采用301重定向进行URL标准化设置。
2、带www和不带www的域名对搜索引擎是同等的,任意选择其中一个作为主域名,在内部链接和友情链接时,都使用主域名,这样不会使PR值分散。
3、如果你的主机不支持301重定向,把首页的所有链接采用绝对地址的链接形式也可以很好解决这个问题。那我们绑定www还是不带www好呢? 站到用户体验和老网民角度来说, 第一页建议绑定带www.然后给不带www做域名转向或者301跳转。这样所有用户量不会少,同时避免重复收录,再者域名不带www做了这样转向百度也同样收录。
附:
.htaccess的301重定向代码
把不带www的域名301到带www的域名
RewriteEngine On
RewriteCond %{http_host} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
“RewriteEngine On”,开启 Rewrite 规则开关;
“RewriteCond”指重写的条件。后面的字符串通过正则表达式进行匹配,匹配字符串以 ^ 开头并以 $ 结尾。此处 %{http_host} 获取当前主机名称。条件为“当主机名称为example.com”时执行下列的重写规则。其中“[NC]”指不区分大小写;
“RewriteRule”,定义一条重写规则。此处含义:跳转到“http://www.example.com/”接上访问请求的网址中 example.com 后面的部分。[R=301] 指重写为 301 重定向/跳转([R] 单指跳转,意义等同 [R=302]),[L] 指最后一条匹配规则。
把老域名301到新域名
更换域名时,老域名的权重不能浪费了,把老域名的顶级域名和带www的域名都要301到新域名,代码如下
RewriteEngine On
RewriteCond %{http_host} ^(www.)?old.com$ [NC,OR]
RewriteCond %{http_host} ^new.com$ [NC]
RewriteRule ^(.*)$ http://www.new.com/$1 [R=301,L]
现在无论你访问old.com,www.old.com,new.com都会301到www.new.com 够完美了吧!而且所有的内页也会跟着301,接下来至少等待2个月,期间不要删除原域名,静等权重完全转移!
需要注意的是,wordpress默认情况下不支持该条命令,因为wordpress的网址本身就是伪静态的,要想实现这个功能,必须先把wordpress的内页生成html文件。
========================================================
Redirect a WordPress site from non-WWW to WWW
The following tutorial will show you how to redirect your WordPress site’s domain from non-www to www or vice versa. Redirecting one to the other is useful for SEO.
If you go to https://www.wordpress.org, you’ll see the URL changes a bit once you click enter. It goes to the non-www version. In order words, it goes to https://wordpress.org. It’s a subtle change and it’s usually not noticed by users.
So why have they done this? It’s because, technically, the two are different domains but they have the same content. Without the redirect, they end up with duplicate content. With the redirect, they only have one site, so only one set of content.
With only one set of content, they guarantee they won’t be penalized by search engines or have their ranking split.
To move your site to non-www, find your .htaccess file using your host’s file manager or an FTP client.
Within it, look for the following code:
RewriteEngine On
If the code isn’t there, insert it at the top of your file.
Then, to redirect non-www to www, use the following code directly below RewriteEngine On:
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
For www to non-www, use:
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
If you’re on a Windows IIS server, the above code won’t work for you.