常规页面的跳转:
在论坛根目录新建一个 301.inc.php 文件,写入以下代码(红色处换成自己的新域名):
<?php
$the_host = $_SERVER['HTTP_HOST']; //取得当前访问域名
$url = $_SERVER['PHP_SELF']; //获取域名后的字串,如:/bbs/index.php
$filename= substr( $url , strrpos($url , '/')+1 ); //提取当前文件名
$querystring = $_SERVER["QUERY_STRING"]; //获取问号后面的参数
if ($the_host !== 'www.seoyj.cn') //验证当前访问域名:若非引号内的域名,则进行如下跳转——
{
if ($querystring !== '') //验证文件名后是否有参数,如果有参数则跳转到——
{
header('HTTP/1.1 301 Moved Permanently'); //发出301头部,表明永久重定向
header('Location: http://www.seoyj.cn/'.$filename.'?'.$querystring); //跳转到我的新域名地址【带参数】
}
else //如果无参数则跳转到——
{
header('HTTP/1.1 301 Moved Permanently'); //发出301头部,表明永久重定向
header('Location: http://www.seoyj.cn/'.$filename); //跳转到我的新域名地址【不带参数】
}
}
?>
然后在每一个需要跳转的PHP页面的 <?php 下面加一行:
include("301.inc.php"); //301重定向
通常需要跳转的是以下几个页面:
index.php
forumdisplay.php
viewthread.php
redirect.php
tag.php
logging.php
space.php
archiver 无图版页面的跳转:
纯文本格式的 archiver 因为是在一个单独的目录,所以跳转代码要单独写。方法如下:
在论坛 /archiver/ 下新建一个 301.inc.archiver.php 文件,,写入以下代码(红色处换成自己的新域名):
<?php
$the_host = $_SERVER['HTTP_HOST']; //取得当前访问域名
$url = $_SERVER['PHP_SELF']; //获取域名后的字串,如:/archiver/?fid-48.html 尽管写作 /?fid-48.html ,实际上相当于 /index.php?fid-48.html
$filename= substr( $url , strrpos($url , '/')+1 ); //提取当前文件名,也就是 index.php
$querystring = $_SERVER["QUERY_STRING"]; //获取问号后面的参数
if ($the_host !== 'www.seoyj.cn') //验证当前访问域名:若非引号内的域名则进行如下跳转——>>
{
if ($querystring !== '') //验证文件名后是否有参数,如果有参数则跳转到——
{
header('HTTP/1.1 301 Moved Permanently'); //发出301头部,表明永久重定向
header('Location: http://www.seoyj.cn/archiver/'.'?'.$querystring); //跳转到我的新域名地址【带参数】
}
else //如果无参数则跳转到——
{
header('HTTP/1.1 301 Moved Permanently'); //发出301头部,表明永久重定向
header('Location: http://www.seoyj.cn/archiver/'); //跳转到我的新域名地址【不带参数】
}
}
?>
然后在 /archiver/index.php 页面的 <?php 下面加一行:
include("301.inc.archiver.php"); //301重定向