404页面的目的是:告诉浏览者其所请求的页面不存在或链接错误,同时引导用户使用网站其他页面而不是关闭窗口离开。
很多开源系统包括CMS系统、Blog系统等不提供404页面或提供的404页面并未达到SEO的要求,这让网站的权威性大打折扣。
404页面该达到怎么样的效果才符合SEO要求?
搜索引擎通过HTTP状态码来识别网页的状态。当搜索引擎获得了一个错误链接时,网站应该返回404状态码,告诉搜索引擎放弃对该链接的索引。而如果返回200或302状态码,搜索引擎就会为该链接建立索引,这导致大量不同的链接指向了相同的网页内容。结果是,搜索引擎对该网站的信任度大幅降低。——很多网站存在这个问题:404页面返回的是200或302状态码而不是404状态码。
正确建立404页面的方法是:(仅适合Apache服务器)
- 在.htaccess 文件中加入代码: ErrorDocument 404 /Error.html
- 建立一个简单的html404页面命名 Error.html
- 把
Error.html放置在网站根目录
注意:
- 不要将404错误直接转向到网站首页,这将导致首页不被收录;
- /Error.html 前面不要带主域名,否则返回的状态码是302或200状态码。
作SEO时,我们经常会在日志上看到类似这样的代码:
61.135.166.232 - - [31/Dec/2007:02:30:11 +0800] "GET /category21.html HTTP/1.1" 200 10968 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)"
66.249.70.172 - - [31/Dec/2007:03:36:10 +0800] "GET /32_10_zh.html HTTP/1.1" 200 18395 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
这里面需要知道的,就是那个奇怪的数字“200”(另外那个数字表示抓取的文件大小)。
“200”就是HTTP状态码。
SEO过程中最常见的HTTP状态码有:
- 200 - 服务器成功返回网页
- 404 - 请求的网页不存在
- 503 - 服务器超时
其他经常碰到的HTTP状态码列表如下:
200
204
重定向3××
301
302
304
客户端错误4××
400
403
404
410
服务器错误5××
500
503
下面是一个完整的.htaccess文件,仅供参考。
##
# if you want to use mod_rewrite, set this 'On'
RewriteEngine On
# the path to your site installation
RewriteBase /
# Maintenance Section - Uncomment the lines below according to your need
# Write below your client IP address (e.g.: 127.0.0.1)
# if you need to keep your web access during maintenance
#RewriteCond %{REMOTE_ADDR}
# Choose your way of closing the access to PMF:
# a. you can simply forbid access (HTTP 403 Error)
#RewriteRule ^(.*)$
# b. return the user an explanation
#RewriteRule ^(.*)$
# url canonicalization
RewriteCond %{http_host} ^seowhy.com [NC]
RewriteRule ^(.*)$ http://www.seowhy.com/$1 [L,R=301]
# show all categories
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the search page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the add content page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the ask question page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the open questions page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the help page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# the contact page
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)$
# a page with a record
RewriteCond %{REQUEST_URI}
RewriteRule ^(.*)_(.*)_(.*)\.html$
# a category page
RewriteCond %{REQUEST_URI}
RewriteRule ^category(.*)\.html$
# a category page with page count
RewriteCond %{REQUEST_URI}
RewriteRule ^category(.*)_(.*)\.html$
# start page
RewriteRule index.html$ index.php [PT]
# sitemap
RewriteCond %{REQUEST_URI}
RewriteRule ^sitemap-(.*)_(.*)\.html$
# a solution id page
RewriteCond %{REQUEST_URI}
RewriteRule ^solution_id_(.*)\.html$
# 404 page
ErrorDocument 404 /404.html