您的位置:首页 > 编程语言

论坛结构改动,URL重写不影响收录地址的访问代码

2008-11-30 20:46 239 查看
关于URL重写,可能有站长需要发下,好查询。
首先需要做的事三个文件,
index.php
read.php
thread.php

做这三个文件放在原来的目录就可以了。

第一种方法有演示。

以下代码能仅把BBS目录移入根目录,
比如吧 http://liulangmao.com/bbs/read.php?tid=16194 重写为http://liulangmao.com/read.php?tid=16194

Copy code
<?php
$a=$_SERVER['URL'];
$a=substr($a,4);
header("location:$a");
?>

以下代码能实现目录为www开头域名重写为bbs开头,并把bbs目录移动到根目录,
比如吧 http://www.liulangmao.com/bbs/read.php?tid=16194 重写为http://bbs.liulangmao.com/read.php?tid=16194

Copy code
<?php
require_once('global.php');
$a=$_SERVER['URL'];
$a=substr($a,4);
$b=$db_bbsurl;
$url = str_replace("www", "bbs", "$b");
//echo $url;
$url=substr($url, 0,-4);
$c=$url.$a;
header("location:$c");
?>

补充一种,同目录下的域名重写。【不推荐使用,百度搜索会当此为作弊】
现在要用的URL地址:http://liulangmao.com
换之前用的URL域名:http://www.liulangmao.com

Copy code
<?php
require_once('global.php');
$url = "http://liulangmao.com".$_SERVER['REQUEST_URI'];
if ($db_bbsurl!="http://www.liulangmao.com")Header("Location:$url");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐