when migrating a blog from blogspot to wordpress, and you want to have the incoming links work without making a 301 redirect for each post, you will need to change the way incoming links are handled after being redirected from blogspot
Generally, blogspot/blogger urls differ from WordPress in the following ways:
1. the domain name (of course).
When redirects are set up at blogspot, the url is changed to the new domain name, and the rest of the url (after the domain) is left the same. If you set up redirection for the blog in blogspot, then this is done.
2. The urls in blogspot end in .html whereas the ones in WordPress end in /
This can be fixed with a simple bit of code added to .htaccess which changes the incoming links to end in / , not .html. The following should be added to the top of your .htaccess file.
# Extra stuff for blogspot redirects RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*).html(.*)$ $1/$2 [R=301,L] RewriteRule ^(.*).htm$ $1/$2 [R=301,L]
3. remove a, an, the from the post slugs.
you will need to change all the permalinks (post_names). This is because blogger omits a, an, the, from post slugs whereas WordPress leaves them in. So, when the posts are imported, the slugs do not match. This is remedied by using the following script to replace the post_name and guid for each post where a, am, the is used.
3-1. Copy this script into functions.php
function remove_articles_from_slugs(){ global $wpdb; // load all post_names $sql = "SELECT ID, post_name FROM wp_posts WHERE post_type = 'post'"; $names = $wpdb->get_results($sql); $repl = array('-a-','-an-','-the-'); if ($names) { echo '<div><strong>Replacing Stings in Post Names</strong> <br /></div>'; $i = 0; $changed = 0; foreach ($names as $name) { $i++; $rawname = $name->post_name; // foreach - string replace -a- , -an- , -the-, with - $thename = str_replace($repl, '-', $rawname); // now test to see if the article is at beginning of the name if( substr($rawname,0,2)== 'a-') { $thename = substr($rawname,2); // cuts off the first two characters } if( substr($rawname,0,3)== 'an-') { $thename = substr($rawname,3); // cuts off the first two characters } if( substr($rawname,0,4)== 'the-') { $thename = substr($rawname,4); // cuts off the first two characters } // now test to see if the article is at END of the name if( substr($rawname,-2)== '-a') { $thename = substr($rawname,0,-2); // cuts off the last two characters } if( substr($rawname,-3)== '-an') { $thename = substr($rawname,0,-3); // cuts off the last three characters } if( substr($rawname,-4)== '-the') { $thename = substr($rawname,0,-4); // cuts off the last four characters } // echo the replacement made, if made if ($thename != $rawname){ // make the update $wpdb->update( 'wp_posts_test', // table array('post_name' => $thename), array('ID' => $name->ID) ); $wpdb->show_errors(); echo '<div>('.$i.') <strong>Replaced</strong> Name '.$rawname.' <strong>with</strong> '.$thename.'</div>'; //exit; $changed++; } else { echo '<div>('.$i.') <strong>No Changes needed </strong> Name: '.$rawname.' </div>'; } // find places where a, an, the, is the last word, and remove those // save the result } // end foreach echo '<br /><br /><div><strong>Finished Replacing strings in Post Names</strong> <br /> Total Names Checked: '.$i.' <br /> Total Names Changed: '.$changed.' <br /><br /><br /> </div>'; }// end if names // do the above for guid // load all post_names $sql2 = "SELECT ID, guid FROM wp_posts WHERE post_type = 'post'"; $guids = $wpdb->get_results($sql2); $repl = array('-a-','-an-','-the-'); $repl2 = array('/a-','/an-','/the-','-a/','-an/','-the/'); if ($guids) { echo '<div><strong>Replacing Stings in Post Guids</strong> <br /></div>'; $i = 0; $changed = 0; foreach ($guids as $guid) { $i++; $rawguid = $guid->guid; // foreach - string replace -a- , -an- , -the-, with - $theguid = str_replace($repl, '-', $rawguid); $theguid = str_replace($repl2, '/', $rawguid); // echo the replacement made, if made if ($theguid != $rawguid){ // make the update $wpdb->update( 'wp_posts_test', // table array('guid' => $theguid), array('ID' => $guid->ID) ); $wpdb->show_errors(); echo '<div>('.$i.') <strong>Replaced</strong> Name '.$rawguid.' <strong>with</strong> '.$theguid.'</div>'; // exit; $changed++; } else { echo '<div>('.$i.') <strong>No Changes needed </strong> Name: '.$rawguid.' </div>'; } // find places where a, an, the, is the last word, and remove those // save the result } // end foreach echo '<br /><br /><div><strong>Finished Replacing strings in Post Guids</strong> <br /> Total Names Checked: '.$i.' <br /> Total Names Changed: '.$changed.' <br /> </div>'; }// end if guids } // end function if($_GET['iam'] == 'testing'){ remove_articles_from_slugs(); }
3-2. Make a backup of your wp_posts table, or backup the whole database
3-3. Run the script by going into any page, not in admin, and typing this at the end of the page: ” ?iam=testing “. This activates the function and makes the replacements
3-4. Remove the function when done.