<?php $name="demo.yourdomain.com.cn"; //网站办事器用的域名 $error="http://demo.yourdomain.com.cn"; //本程序出错.不匹配时转向的域名 /////////////不要修改 $host = getenv( "HTTP_HOST" ) ? getenv( "HTTP_HOST" ) : $_SERVER['HTTP_HOST']; $path=str_replace(".$name","",$host); if (($host == $name) or !strpos($host,$name) or !is_dir($path)) { header("Location: $error"); exit; } $new="http://".$name."/".$path; header("Location: $new"); ?>