Created
October 8, 2008 21:03
-
-
Save brendano/15594 to your computer and use it in GitHub Desktop.
blogger -> wordpress redirect code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* *** THIS NEEDS TO BE EDITED FOR A NEW INSTALLATION *** | |
* | |
* this is supposed to be called as e.g. | |
* http://anyall.org/blog/blogger/http://socialscienceplusplus.blogspot.com/2008/10/mydebatesorg-and-poten | |
tially-coolest.html | |
* and then redirect to e.g. | |
* http://anyall.org/blog/2008/10/mydebatesorg-online-polling-and-potentially-the-coolest-question-corpus- | |
ever/ | |
* | |
* It accesses wordpress's own metainfo saved from the blogger migration, | |
* to guarantee redirection to the correct new version -- no hacks with strings. | |
* | |
* So there are 2 redirects total: | |
* (1) the blogspot.com page meta-refreshes to here | |
* (2) this "page" sends to the final wordpress post url | |
* | |
* This script is "installed" by placing it directly in the wordpress root. | |
**/ | |
require_once( dirname(__FILE__) . '/wp-load.php' ); | |
wp(); | |
//print_r($wpdb); | |
$path = $_SERVER['PATH_INFO']; | |
$path = preg_replace('/^\/+/', '', $path); | |
$path = preg_replace('/^https?:\/+socialscienceplusplus\.blogspot\.com/','/', $path); | |
$path = preg_replace('/^\/+/', '', $path); | |
$path = "/" . $path; | |
//echo $path; | |
$res = $wpdb->get_results( | |
$wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='blogger_permalink' AND meta_value = '% | |
s'", $path) ); | |
//print_r($res); | |
if (count($res)==0) { | |
//echo "Error, path '$path' matches no blogger imports."; | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: http://anyall.org/blog/"); | |
} else if (count($res) > 1) { | |
echo "Error, path '$path' matches many blogger imports."; | |
} else { | |
$post_id = $res[0]->post_id; | |
//print_r($post_id); | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: http://anyall.org/blog/?p=$post_id"); | |
exit(); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
*** THIS NEEDS TO BE EDITED FOR A NEW INSTALLATION *** | |
stick this in anywhere in the <head> .. only on a "Classic" | |
blogger template. They also have a newer XML-based template language, | |
but it can't support this usage because it's too strictly proper xml | |
and can't do the string concatenation trick we need. --> | |
<Blogger> | |
<MainOrArchivePage> | |
<meta http-equiv="refresh" content="0;url=http://anyall.org/blog/" /> | |
</MainOrArchivePage> | |
<ItemPage> | |
<meta http-equiv="refresh" content="0;url=http://anyall.org/blog/blogger/<$BlogItemPermalinkUrl$>" /> | |
</ItemPage> | |
</Blogger> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment