<?php
//PHPCMS转换成帝国CMS后,链接地址改变,百度搜索结果转换
//提前建好数据表,包括三个字段,id,oldurl,newurl
//本文件任意命名(例:abc)放在根目录下
//htaccess 配置跳转,rewrite ^(.*)/content-(.+)-(.+)-(.*)$ $1/abc.php?id=$3 last;
//数据库配置
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "dbname";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
if(is_array($_GET)&&count($_GET)>0){
if(isset($_GET[id])){
$id=$_GET[id];//存在
$sql = "SELECT * FROM tablename where id=$id";
$result = $conn->query($sql);
}
}
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$newurl=$row["newurl"];
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$newurl); // 输出数据
}else{
header('Location: http://www.abc.com');
}
$conn->close();