简单几个步骤为你的博客添加404页面

404页面是网站必备的一个页面,它承载着用户体验与SEO优化的重任。404页面通常为用户访问了网站上不存在或已删除的页面,服务器返回的404错误。如果站长没有设置404页面,会出现死链接,蜘蛛爬行这类网址时,不利于搜索引擎收录。                     ---摘自百度百科

简单几个步骤为你的博客添加404页面

为什么写这篇文章呢,因为我发现zblog的主题大部分都没有带404页面的模板,那么这时候就需要我们自己动手做一个了。

首先我们打开主题所在的文件夹下的template文件夹,在里面新建一个404.php文件,然后按需要修改以下代码,并加入在404.php文件中

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>烽烟博客-404</title><!-- 网页标题 -->
<link rel="stylesheet" media="screen" href="style.css"><!-- css文件地址 -->

<script language="JavaScript">
function dosearch() {
var sf=document.searchform;
var submitto = sf.sengine.value + escape(sf.searchterms.value);
window.location.href = submitto;
return false;
}
</script>
</head>
<body>

<div>
<img src="images/Logo.png" /><!-- logo地址 -->
</div>

<p>404</p>

<div>
<h2>很遗憾的通知您,您访问的页面不知去向了!</h2>

<p>
可能是攻城狮或者也可能是程序猿觉携带此页面跑路了;或者也可能是页面被外星人绑架了,反正不管怎么样我们的技术人员正在积极的查找原因,您可以继续浏览以下分类!

<!-- 在这里输入详细的描述 -->
</p>

<p>
<a id="button" href="http://fengyan.cc">&larr; 返回首页</a> <a href="#">分类一</a> <a href="#">分类二</a> <a href="#">分类三</a> <a href="#">分类四</a>
<!-- 可以在此处添加分类链接 -->
</p>
</div>

</body>
</html>

保存php文件后,在新建一个css文件将以下代码加入文件中

@-webkit-keyframes appear{
	from{
		opacity: 0;
		}
	to 	{
		opacity: 1;
	}
}

@-webkit-keyframes headline_appear_animation{
	from{
		opacity: 0;
	}
	25% {
		opacity: 0;
	}	
	to 	{
		opacity: 1;
	}
}

@-webkit-keyframes contentappear{
	from {
		-webkit-transform: scale(0);
		opacity: 0;
	}
	50% {
		-webkit-transform:  scale(0.5);
		opacity: 0;
	}
	to {
		-webkit-transform: scale(1);
		opacity: 1;
	}
}

@-moz-keyframes appear{
	from{
		opacity: 0;
		}
	to 	{
		opacity: 1;
	}
}

@-moz-keyframes headline_appear_animation{
	from{
		opacity: 0;
	}
	25% {
		opacity: 0;
	}	
	to 	{
		opacity: 1;
	}
}

@-moz-keyframes contentappear{
	from {
		-moz-transform: scale(0);
		opacity: 0;
	}
	50% {
		-moz-transform:  scale(0.5);
		opacity: 0;
	}
	to {
		-moz-transform: scale(1);
		opacity: 1;
	}
}

* {
	margin: 0;
	padding: 0;
}



a:active{
	position: relative;
	top: 1px;
}

html{/*背景图片地址*/
	background: url(backgrounds/background-3.png) no-repeat center center fixed;
	
	-webkit-background-size: cover;
	-moz-background-size: cover;
	-o-background-size: cover;
	background-size: cover;
}

body{
	font-family: 'Helvetica Neue';
	width: auto;
	margin: 0 auto 100px auto;
}

.header {
	position: fixed;
	top: 0;
	width: 100%;
	height: 55px;
	padding: 0 0 0 10px;
	
	color: #fff;
	background-image: -moz-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	background-image: -o-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	background-image: -webkit-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0,1));
	background-image: linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	border-top: 1px solid #000;
	box-shadow: inset 0px 1px rgba(255, 255, 255, 0.4),
				0px 0px 13px #000000;
				
	z-index: 99;
	-webkit-animation: 1s appear;
	-moz-animation: 1s appear;
}

p.error {
	color: #000;
	text-shadow: #fff 0 1px 0;
	text-align:center;
	font:900 25em helvetica neue;
	-webkit-animation: 2s headline_appear_animation;
	-moz-animation: 2s headline_appear_animation;
	  					 
}

.content {
	margin: auto;
	padding: 30px 40px 40px 40px;
	width: 570px;
	
	color: #fff;
	-webkit-animation: 2s contentappear;
	-moz-animation: 2s contentappear;
	background-image: -moz-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	background-image: -o-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	background-image: -webkit-linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0,1));
	background-image: linear-gradient(top, rgba(85, 85, 85, 0.7), rgba(0,0,0, 1));
	border: 1px solid #000;
	box-shadow: inset 0px 1px rgba(255, 255, 255, 0.4),
				0 3px 8px #000000;
	border-radius: 6px;
	
	font: 16px;
	line-height: 25px;
	font-weight: 300;
	text-shadow: #000 0 1px 0;
}

.content h2{
	text-transform: uppercase;
	text-align: center;
	padding-bottom: 20px;
}

form {
	height: 40px;
}

.inputform {
	font: 12px;
	border: none;
	padding: 10px;
	width: 300px;
	margin: 15px 0 0 75px;
}

.button {
	width: 100px;
	margin-top: 1px;
	height: 33px;
	border: none;
	
	text-shadow: #fff  0 1px 0;
	background-image: -moz-linear-gradient(top, #ffffff, #aaa);
	background-image: -o-linear-gradient(top, #ffffff, #aaa);
	background-image: -webkit-linear-gradient(top, #ffffff, #aaa);
	background-image: linear-gradient(top, #ffffff, #aaa);
	box-shadow: inset 0px 1px rgba(255, 255, 255, 1);
}

.button:hover {
	background-image: -moz-linear-gradient(top, #ffffff, #ccc);
	background-image: -o-linear-gradient(top, #ffffff, #ccc);
	background-image: -webkit-linear-gradient(top, #ffffff, #ccc);
	background-image: linear-gradient(top, #ffffff, #ccc);
	cursor: pointer;
}

.button:active {
	background-image: -moz-linear-gradient(top, #ccc, #fff);
	background-image: -o-linear-gradient(top, #ccc, #fff);
	background-image: -webkit-linear-gradient(top, #ccc, #fff);
	background-image: linear-gradient(top, #ccc, #fff);
}

p.links {
	margin: 24px 0 0 0;
	text-align: center;
}

p.links a {
	color: #fff;
	margin-left: 15px;
	margin-right: 15px;
}

p.links a:hover {
	text-decoration: none;
	text-shadow: #fff 0 0 5px;
	-webkit-transition: all ease-in 0.3s;
	-moz-transition: all ease-in 0.3s;
}

好了,如果以上的几个步骤你没有出错的话,那么打开网站看看效果吧!

最后编辑于:2015/03/29作者: 烽烟无限