|
补充: 8 G3 m9 u: B$ o1 u! |
1、以下代码只适用于网站域名更换的情况下,即不同的域名和不同的空间根目录,把上面代码放置于旧站网站文件的顶部即可,这时访问旧站时就会重定向到新站www.xp37.com。如果网站是属于一个网站空间绑定2个域名,2个域名的根目录为同一个时,那么就会出现死循环了。 " j/ P E( i' S% o
ASP代码: <% Response.Status=”301 Moved Permanently” Response.AddHeader “Location”,”http://www.xp37.com” Response.End %> PHP代码: <? Header( “HTTP/1.1 301 Moved Permanently” ); Header( “Location: http://www.xp37.com” );?> 1 W3 |& h' r4 @6 C& c; a2 l* Q. x
% d3 s* S3 B, j! R0 ^8 [8 g
2、如果是一个网站绑定多个域名情况,将不带WWW的子域名或其他域名重定向到一个主域名,那么只需要加个判断: ASP重定向代码: <% if request.ServerVariables(“HTTP_HOST”)="xp37.com” then Response.Status=”301 Moved Permanently” Response.AddHeader “Location”,”http://www.xp37.com” Response.End end if %> PHP重定向代码: <?php $the_host = $_SERVER['HTTP_HOST'];//取得进入所输入的域名 $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ”;//判断地址后面部分 if($the_host !== ‘ccanju.com’)//旧域名或子域名地址 { header(‘HTTP/1.1 301 Moved Permanently’);//发出301头部 header(‘Location: 跳转到我的新域名地址 } ?> 这时访问xp37.com就会301重定向到www.xp37.com了。
# U2 Z+ w4 `& | u2 m
% L8 o% [" [0 `1 t' a6 @dede的301跳转例子 # ]# h. s1 D( S7 o1 A# H/ b% o
; g7 D9 X, r" W: I7 X* ^
强调一点:我们是将index.php的优先级设为比index.html高:
) H& {6 n5 E- J% H第一种方法:更改跟目录下的index.php文件
5 m& o V7 J5 Q v. m1 C" g7 M& Y <?php ! W/ I, e7 A8 |; h. i: l. ?0 g5 l/ m
if(!file_exists(dirname(__FILE__).'/data/common.inc.php')) : X( V( B( l/ C4 q8 E0 D
{
% R1 A4 b6 [# I0 }% I, [ header('Location:install/index.php'); exit(); } //自动生成HTML版 if(isset($_GET['upcache'])) { require_once (dirname(__FILE__) . "/include/common.inc.php"); require_once DEDEINC."/arc.partview.class.php"; $GLOBALS['_arclistEnv'] = 'index'; $row = $dsql->GetOne("Select * From `dede_homepageset`"); $row['templet'] = MfTemplet($row['templet']); $pv = new PartView(); $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']); $pv->SaveToHtml(dirname(__FILE__).'/index.html'); include(dirname(__FILE__).'/index.html'); exit(); } else{ /* header('HTTP/1.1 301 Moved Permanently'); header('Location:index.html');*/ $domain = explode(".", $_SERVER['HTTP_HOST']); if(count($domain)==2 && $domain[0]=='ccanju.com'){ header('HTTP/1.1 301 Moved Permanently'); header('Location:http://www.ccanju.com/'); }else{ include(dirname(__FILE__).'/index.html'); } exit(); } ?> 第二种
$ t0 Y2 U- O$ T8 P( i<?php
8 f0 a' \; h6 K w) c! Q4 ]$ ~" c$HOST=$_SERVER['HTTP_HOST']; if ($HOST=="ccanju.com"){ Header("HTTP/1.1 301 Moved Permanently"); Header("Location:http://www.ccanju.com"); exit(); } if(!file_exists(dirname(__FILE__).'/data/common.inc.php')) { header('Location:install/index.php'); exit(); } require_once (dirname(__FILE__) . "/include/common.inc.php"); require_once DEDEINC."/arc.partview.class.php"; $GLOBALS['_arclistEnv'] = 'index'; $row = $dsql->GetOne("Select * From `dede_homepageset`"); $row['templet'] = MfTemplet($row['templet']); $pv = new PartView(); $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']); $pv->Display(); ?>
\8 S; U3 _, X3 _- p
开始的时候我用的上面的例子弄的 不过都没有实现效果 * Q; ]: d% [7 I6 q( p9 x
因为我的也是套用模板程序的网站 后来想起dede也是模板类得 所以就找了dede的例子 * O6 t1 K$ T4 G& A+ \, E# F2 k7 F
最后在根目录下的index.php下面修改的代码
' m) Y @- X, V7 v! R' u( k<?php ! F) x0 _, L3 O4 _
$HOST=$_SERVER['HTTP_HOST']; if ($HOST=="ccanju.com"){ Header("HTTP/1.1 301 Moved Permanently"); Header("Location:http://www.ccanju.com"); exit(); } require('path.inc.php');
/ m1 E5 ?! `3 }* |4 F) K+ c ?>
1 z5 k: \4 `4 g* F0 r( s" k成功实现跳转 . ]! j. X- W* ~! `
[此贴子已经被作者于2012-11-13 15:30:15编辑过] x: B; Q; D+ r/ J
|