-2

I'm just learning on my own how PHP works but I need to find out how to do this immediately because I'm moving away from my wiki page to another content management system. Here's my dilemma, I want to redirect my old wiki pages to another CMS with a different ID.

I need to create a file that will run when someone goes to my wiki that will redirect to the other CMS both of which use PHP.

Is this possible, I've been looking high and low and for some reason I can't find the answer.

ChrisW
  • 4,970
  • 7
  • 55
  • 92
  • Can you describe the structure of your old and new URLs? Do you already use Rewrite Rules? – DerVO Jan 31 '12 at 13:17
  • You could either let the webservice do it for you (e.g. apache / .htaccess) or you can setup a PHP trhough which all requests will go and redirect there. P.S why is your question tagged wikipedia? – PeeHaa Jan 31 '12 at 13:17
  • Do you mean that if someone goes to www.yoursite.com/wiki/index.php you want them to be redirected to www.yoursite.com/othercms/index.php? – ChrisW Jan 31 '12 at 13:18
  • What's the name of your new CMS? I might have built in routing capabilities. – The Silencer Jan 31 '12 at 13:19

3 Answers3

2

You'll want to send two headers.

http://us.php.net/manual/en/function.header.php

The first, a moved permanently header, then the new location. How you map the changes is up to you, this will be the last step.

$url = 'new destination';
header ('HTTP/1.1 301 Moved Permanently');
header ("Location: $url");
MetalFrog
  • 9,943
  • 1
  • 22
  • 24
  • Just something to keep in mind. 301 redirects can severely hurt your search engine rankings. I would recommend dropping the `header ('HTTP/1.1 301 Moved Permanently');` if you are building this site for optimal search engine rankings, as it is not required for a redirect. – Oliver Spryn Jan 31 '12 at 13:20
1
$old_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if($old_id)
{
    $new_id = getNewId($old_id);
    if($new_id)
    {
        $newlocation = "http://mysite.com/newpage.php?id=".$new_id;
        header("HTTP/1.1 301 Moved Permanently");
        header("Location: {$newlocation}");
    }
}
die();
Seagull
  • 3,319
  • 2
  • 31
  • 37
0

This is a very tedious work to do.

Well pretend your old ids reside in a database table and you new ids in a different database table (event in a different database). Then you must translate the old one to the new one. But how to find out? This the part were you need some inspection inside the databases

yunzen
  • 32,854
  • 11
  • 73
  • 106