php 建站 多域名配置 自定义重定向

1. 申请一个域名 , 当多个域名使用。

比如 申请一个顶级域名为 .com 后缀的一级域名 :mine.com,

一般允许绑定四五个二级域名,比如 www.mine.com  、 mine.mine.com

2. 给自己网站来个重定向 

如果是静态网站,自己写个正则匹配方法,根据 url 特殊字符串 重定向到对应的页面上去。

如果是 动态网站,比如是 php 构建的,也是一样的根据 二级域名的不同 重定向到对应页面上去。

3.  index.php 代码

$site=$_SERVER['SERVER_NAME'];
if(preg_match('/dep./',$site)){
header("Location: index.htm");   
exit();
}


if(!file_exists(dirname(__FILE__).'/data/common.inc.php'))
{
    header('Location:install/index.php');
    exit();
}
//自动生成HTML版
if(isset($_GET['upcache']) || !file_exists('index.html'))
{
    require_once (dirname(__FILE__) . "/include/common.inc.php");
    require_once DEDEINC."/arc.partview.class.php";
    $GLOBALS['_arclistEnv'] = 'index';
    $row = $dsql->GetOne("Select * From `#@__homepageset`");
    $row['templet'] = MfTemplet($row['templet']);
    $pv = new PartView();
    $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);
    $row['showmod'] = isset($row['showmod'])? $row['showmod'] : 0;
    if ($row['showmod'] == 1)
    {
        $pv->SaveToHtml(dirname(__FILE__).'/index.html');
        include(dirname(__FILE__).'/index.html');
        exit();
    } else { 
        $pv->Display();
        exit();
    }
}
else
{
    header('HTTP/1.1 301 Moved Permanently');
    header('Location:index.html');
}
?>

4. 相关文章

二级域名、三级域名

php重定向页面的三种方式

php中正则表达式详解

有效提升香港服务器访问速度的几种方法

原文地址:https://www.cnblogs.com/justSmile2/p/10510758.html