Internal links not updated after fixing permalinks


#1

Hi everybody,

I migrated my wife’s Blogger.com blog to Wordpress using your description at https://rtcamp.com/blogger-to-wordpress/tutorials/permalink-seo-migration/. Very good article, thanks! However I faced the following problem:

After the step “Fixing permalinks for imported post” all posts have the same URL they had at Blogger (fine), but the internal links within posts were not updated to this structure. So for example the URL of an article is:

http://www.bombaypirate.com/2010/08/welcome-to-wordpress-this-is-your-first.html

but a link to this article in another article is still:

http://www.bombaypirate.com/2010/08/welcome-to-wordpress-this-is-your-first-post-edit-or-delete-it-then-start-blogging.html

Is there a way to solve this problem without editing 1000 links manually?

Thanks in advance Hendrik


#2

@Hendrik_Blockus

You can try search & replace plugin to change URLs inside post content. Hope that will help you.

Thanks,

–Nitun


#3

Thanks for your reply @nitunlanjewar. Yes, some kind of search and replace with regular expressions is a good idea. However I don’t know how to exactly generate these short Blogger.com URLs. I somehow have to transfer what you did with the permalinks (script below) to the search and replace plugin.

<?php require_once('wp-load.php'); $res = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_permalink'"); $wpdb->print_error(); foreach ($res as $row){ $slug = explode("/",$row->meta_value); $slug = explode(".",$slug[3]); $wpdb->query("UPDATE $wpdb->posts SET post_name ='" . $slug[0] . "' WHERE ID = $row->post_id"); $wpdb->print_error(); } echo "DONE"; ?>

#4

That php script will only work with post URLs depends on slug, it will not search URL under post content.


#5

Yes I know. I just meant that I need to do something similiar for links within posts, but I don’t know how. How are the Blogger.com built?

In your example below only the first 7 words are used for the Blogger URL. But this is not a fixed number. Sometimes more or less words are used.

http://www.bombaypirate.com/2010/08/welcome-to-wordpress-this-is-your-first-post-edit-or-delete-it-then-start-blogging.html

http://www.bombaypirate.com/2010/08/welcome-to-wordpress-this-is-your-first.html


#6

That could be a more complicated things to first identify post URL (that must be your blog post URL) under post content by writing a php/SQL script and then you must write a code to map first word in URL with other existing URL which actually changed after fix.php file. And at the last update script to change those URL. I think this is how its complex. :expressionless:

blogger.com skip English vowels from URL along with “the” and some other words, and make smaller URL. But WordPress use the complete post title as a slug.


#7

Thanks! Regarding the complexity I think editing the links manually seems to be the faster way.


#8

Is it not possible to use the wp-cli (http://wp-cli.org) “Search & Replace” functions?


#9

Yeah, that will be a good option. :slight_smile:


#10

There are about 600 broken links within my blog posts. Most of them go to different URLs. So a normal search & replace would not do the trick. If it was just the domain name or some other common string, search & replace would be a good idea of course.


#11

@Hendrik_Blockus

I think you may be pleasantly surprised. How about a “Dry Run” to see? Try:

wp search-replace 'http://example.dev' 'http://example.com' --dry-run

…paying special attention to the “Dry Run” flag, as it will go through the motions, but not make any changes.

From: http://wp-cli.org/commands/search-replace/

[–dry-run]
     Show report, but don’t perform the changes.

Or maybe:

wp search-replace 'http://example.dev' 'http://example.com' --recurse-objects --dry-run

…which I understand should dig into the theme and plugin files.

From: http://wp-cli.org/commands/search-replace/

[–recurse-object]
     Enable recursing into objects to replace strings.

Add the:

--network

…flag if it is a network install (WPMU).


#12

@bamajr Thanks for your detailed explanation. It think I have to explain my problem a little further. Currently I have a few hundred internal links in the blog like these two examples:

http://diabetes-leben.com/2014/09/nach-143-gelaufenen-kilometern-in-24-stunden-aufs-siegertreppchen-gehievt.html

http://diabetes-leben.com/2011/12/insulin-purging-erbrechen-ueber-die-niere.html

The only interesting part is the part after the last slash. These links do not work as the correct Permalinks for these examples are:

These permalinks where created with the fix.php presented on this website which applies a certain mechanism to shorten the links as shown. So I have a few hundred different links where I have to change the *.html with such a mechanism. I think this cannot be done via simple search and replace.


#13

Indeed, search and replace can not help here. I have recently migrated my site www.roulette30.com from blogger to WP. So I can relate. But what you describe as your problem, doesn’t make sense.

You have a site on blogger. Your permalinks are Blogger-type. The internal links are pointing to Blogger-type permalinks.

Then you move to WP. You fix your permalinks to be Blogger-type or in other words to be the same that they were in Blogger. How is it possible that your internal links (that were imported with your posts from Blogger) suddenly changed from Blogger-type to something else? It’s impossible.

The only case I can think of, is that those links were created after you migrated to WP and before you fixed your permalinks.


#15