Username:
Password:
    Forgot your password?
Member Login

Mapping Old Links into Sitellite

Notes

Chat Loading chat status
  • Please subscribe to chat.
  • Older messages can be viewed in the chat archive.

Subscribe  |  The Lounge  |  Share Lesson

Chapter 3: Mapping the Old Site

You should now have a file named old_links.txt which contains a list of pages that existed on the old site that people have referred to. You will need to modify this file to identify the new pages in Sitellite that the old pages should correspond with. Any pages that don't correspond should be omitted, in which case we'll direct them either to the new web site index, or to a custom Sitellite 'page not found' page (your choice).

To do this, edit the old_files.txt file and add the Sitellite page ID of each page that should be mapped, followed by a tab character, to the beginning of each line of the file. When you're finished, your old_links.txt file should look something like this:

about_us	/about_us.html
contact_us	/contact_us.html
products	/products.html
services	/services.html

Making the error handler script

Now we're ready to create the 404 error handler script which will forward users based on the requested document. Save the following to a file called old_links.php in your web site document root:

<?php

$pages = file ('old_links.txt');

foreach ($pages as $key => $value) {
	list ($id, $old) = explode ("\t", $value);

	if ($_SERVER['REQUEST_URI'] == $old) {
		header ('HTTP/1.1 301 Moved Permanently');
		header ('Location: /index/' . $id);
		exit;
	}
}

header ('Location: /index');
exit;

?>
If you want to use a custom error handler instead of forwarding unknown 404 errors to the index page, you can simply specify that in the last header() call in the script.

Setting the ErrorDocument configuration

The last step is to tell Apache to use our new error handler. To do this, open up your .htaccess file and add the following line to the bottom of it:

ErrorDocument 404 /old_links.php
Now any broken links caused by your web site redevelopment should be forwarded automatically to the appropriate pages on your new web site.