Moving wordpress bolg… how to keep old links working
If you plan to shift your Wordpress blog from old directory to another on the same host, one of the problem you would face is what about the incoming links to the post or what about the links on the search engine results.
Lets take this scenario and some simple solution:
- Your Blog was initially installed at http://yoursite.com/blog
- You shifted it to the top level at http://yoursite.com. (see the following link how to do this: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory )
- Your original links to your posts will be like this http://yoursite.com/blog?p=22 (the number may vary, I am also assuming that your links are set to query string method)
- If you have followed the procedure form wordpress for the same, you know that your index.php had to be moved to the top level of the site i.e http://yoursite.com
- So when a person follows the old link, the person either gets to see an error or a listing of the blog directory (which is not good, both the cases).
- So how do you redirect it to the new location.
- Here is some code to do the same
- Write the following code and save it as index.php under the old blog directory (i.e http://yoursite.com/blog/)
-
<?php
$qs = $_SERVER['QUERY_STRING']; // this fetches the query string i.e the page id.
$newurl = ‘http://yoursite.com/?’.$qs; // new location is ready
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Redirecting…</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″>
<!– send the user to new location –>
<META http-equiv=”refresh” content=”2; url=<? echo $newurl; ?>”>
</head>
<body>
Redirecting……
</body>
</html>
- So now your old links will work magically
- BTW your are free to use the above at you own risk.





