Converting a Wiki to static PHP pages

I used PhpWiki to create my tutorials in the past, but I decided that it was restricting me from doing certain things and had too much overhead for my simple tutorials. I decided that I would just hard code the tutorials in PHP, but I knew that in doing so, the traffic from my site from search engines would pull up 404 errors. I really didn't want that to happen and I know that some search engines take forever to reindex a site.

A wiki will usually only use one page, but will dynamically load data into that page to make it look different. Most wiki URLs will look similar to www.domain.com/tutorial/index.php/My Page. The wiki is actually using just one page, index.php. This actually makes it very easy on us, because then we only have to create one page called index.php, and redirect the My Page part of the request to the new static PHP page, such as www.domain.com/tutorial/mypage.php.

We need to send a code to the search engines to tell it that the old URL that they have is no longer valid and to replace it with the new one. You have to send this in the HTML Header, which is sent by the web server. To do this, you have to put a PHP script at the very top of your new page, without comments, whitespace, or anything else before it:

<?php	//please note that this should be the very first thing on the page
		//no spaces or anything before the opening php tag
function redirect($to) {
if (headers_sent()) return false;
else {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://$to");
exit();
}
}
$path = parse_url($REQUEST_URI);
switch($path[path]) { //put the path to the tutorial here, but do not put the domain
case "/wiki/index.php/Tutorial%20One": if (!redirect("www.n01getsout.com/tutorials/one.php")) { //for some reason, we could not redirect them echo "<HTML><BODY><P>Something went wrong.</P></BODY></HTML>"; } break; //please not that on this case, we have to use both the parenthesis //and the url code to recognize both case "/wiki/index.php/Tutorial%20(Two)": case "/wiki/index.php/Tutorial%20%28Two%29": if (!redirect("www.n01getsout.com/tutorials/two.php")) { //for some reason, we could not redirect them echo "<HTML><BODY><P>Something went wrong.</P></BODY></HTML>"; } break; default: //they came here with a current URL ?>
<HTML> <BODY> Here is a list of my tutorials... </BODY> </HTML> <?php
} //this closes the switch statement
?>

As you can see in the preceding code, you have to catch each page that you want to redirect. Be careful with special characters such as parenthesis, as you will have to catch the actual parenthesis and their URL code. I am unsure of why you have to do this, but that's just what I have experienced. The default case is what the user will get if they just went to www.domain.com/tutorial/index.php.