Skip to content

Instantly share code, notes, and snippets.

@sethladd
Created March 10, 2010 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethladd/327600 to your computer and use it in GitHub Desktop.
Save sethladd/327600 to your computer and use it in GitHub Desktop.
Migrate from Wordpress to Blogger
<VirtualHost *>
ServerName blog.semergence.com
DocumentRoot /var/www/blog.semergence.com
ErrorLog /var/log/apache2/blog.semergence.com-error.log
CustomLog /var/log/apache2/blog.semergence.com-access.log common
ErrorDocument 404 /redirect-to-blogger.php
RewriteEngine On
RewriteRule ^/$ http://blog.sethladd.com/ [R=301]
RewriteRule ^/feed http://blog.sethladd.com/feeds/posts/default [R=301]
RewriteRule ^/category - [G]
<Directory /var/www/blog.semergence.com>
Order allow,deny
Allow From All
AllowOverride All
</Directory>
</VirtualHost>
<?php
$pattern = "{^/(\d{4})/(\d{2})/\d{2}\/(.*)/$}";
preg_match($pattern, $_SERVER['REDIRECT_URL'], $matches);
if (empty($matches)) {
header("HTTP/1.1 404 Not Found");
exit();
}
$year = $matches[1];
$month = $matches[2];
$slug = $matches[3];
// blogger removes common words
function filter($val) {
switch ($val) {
case 'the':
case 'a':
case 'an':
case '.':
return false;
default:
return true;
}
}
$slug = implode('-', array_filter(explode('-', $slug), "filter"));
// blogger only has less than 39 characters
while (strlen($slug) > 39) {
$slug = substr($slug, 0, strrpos($slug, '-'));
}
// blogger doesn't like underscores
$slug = str_replace('_', '', $slug);
$redirect = 'http://blog.sethladd.com/'.$year.'/'.$month.'/'.$slug.'.html';
header("HTTP/1.1 301 Moved Permanently");
header('Location: ' . $redirect);
?>
@Orangery-DS
Copy link

This is just the app what I need but I have no idea how to get it running. Can you please advise, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment