# EP主机 - 日常维护（一） - 自定义错误页

**URL:** <https://forum.rainyun.com/t/topic/30>\
**Category:** 虚拟主机 RVH\
**Created:** [2019 年3 月 22 日 16:00 UTC](https://forum.rainyun.com/t/topic/30 "2019-03-22T16:00:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![admin1](https://forum.rainyun.com/user_avatar/forum.rainyun.com/admin1/32/7_2.png) [@admin1](https://forum.rainyun.com/u/admin1)\
发布日期： [2019 年3 月 22 日 16:00 UTC](https://forum.rainyun.com/t/topic/30/1 "2019-03-22T16:00:00Z")

</div>

页面未找到就提示页面跑丢了？没关系，自定义错误页可以友好地告诉用户页面不存在，而不至于是无法访问网页！  
阅读完此教程，您将学会：

- 如何自定义错误页（全局）

方式：  
将脚本放置在自己的主机里，随时随心调用，高度自由

**调用方式：** 直接访问（即GET）  
**调用示例：** `https://yourdomain.com/somefile.php?code=404&title=404 - 页面未找到&desc=Error code: 404&sec=5&to=https://yourdomain.com/index.php`  
**参数说明：**

- code：错误代码（位置看效果图）
- title：提示信息大字（位置看效果图）
- desc：提示信息小字（位置看效果图）
- sec：跳转秒数
- to：跳转链接

**设置方式：**

 ![3002986262](https://forum.rainyun.com/uploads/default/original/1X/82970d349dcf2d4fac8703bf834e23d65d529ad9.jpeg)  
**调用效果图 及 参数位置对照：**  
 ![4263564724](https://forum.rainyun.com/uploads/default/original/1X/cd7de67a870f28767f2369429d04c25e9f06f934.png)  
（5秒倒计时结束后，[你将会被重定向到yourdomain.com](http://xn--yourdomain-cy4ph0aw7znygyu5alqbj980bom8a.com)）

脚本源代码（PHP）：

```auto
<?php
/ **CODED BY JONJS** /

$code = $_GET["code"]; //错误代码
$title = $_GET["title"]; //提示_大字
$desc = $_GET["desc"]; //提示_小字
$sec = $_GET["sec"]; //跳转秒数
$to = $_GET["to"]; //跳转链接

/**
    GET示例：
    http://url/errorPage.php?code=404&title=404-页面未找到&desc=抱歉，您访问的页面未找到&sec=5&to=https://aoaoao.bid/index.php
**/

$TEXT = '
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>'.$code.'</title>

    <meta http-equiv="refresh" content="'.$sec.';url='.$to.'">
    <style type="text/css">
    body {
        color: #444444;
        background-color: #2166b4;
        font-family: "微软雅黑", sans-serif;
        font-size: 80%;
    }
    h1 { font-size: 21px; }
    h2 { font-size: 15px; }
    #page{
        background-color: #2166b4;
        width: 60%;
        margin: 24px auto;
        padding: 12px;
        margin-top: 100px;
    }
    #header {
        padding: 6px ;
        text-align: left;
        font-size: 100px;
    }
    .status3xx { background-color: #2166b4; color: #FFFFFF; }
    .status4xx { background-color: #2166b4; color: #FFFFFF; }
    .status5xx { background-color: #2166b4; color: #000000; }
    #content {
        padding: 4px 0 24px 0;
        color: #FFFFFF;
    }
    #content a {
        color: #FFFFFF;
    }
    #footer {
        color: #666666;
        background: #2166b4;
        padding: 10px 20px;
        border-top: 5px #2166b4 solid;
        font-size: 0.8em;
        text-align: center;
    }
    #footer a {
        color: #FFFFFF;
    }
    </style>
<style>html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}</style></head>
<body>
    <div id="page">
        <div id="header" class="status4xx">
        '.$title.'
        </div>
        <div id="content">
            <h1>即将返回主页 ( <span id="second">'.$sec.'</span> Sec
            <script type="text/javascript">
                var o=document.getElementById("second");
                window.setInterval("o.innerHTML=parseInt(o.innerHTML)-1;",1000);
            </script> )</h1>
            <h2>'.$desc.'</h2>
        </div>
    </div>
</body>
</html>
';

if($code && $title && $desc && $sec && $to) {
    echo $TEXT;
} else {
    echo "未知来源";
}

```

放入您的主机内，然后仿照调用示例进行调用和设置！
