Maintain permalinks moving from Blogger to WordPress

WordPress’s excellent import script for Blogger doesn’t use the original post slug—necessary for maintaining the permalinks of imported posts. Instead the importer creates new post slugs based on the post titles, which diverges notably from those generated by Blogger because:

  • Blogger truncates the title much sooner than WordPress (less than 40 characters in length)
  • Blogger excludes English article words (a, an, the)
  • Blogger drops characters with accents, instead of converting them to their closest ASCII equivalent

So for example, a post title like:

Los viernes, música para tu iPod en iPod Noticias

gets dirified by Blogger as:

los-viernes-msica-para-tu-ipod-en-ipod

as compared to what WordPress produces:

los-viernes-musica-para-tu-ipod-en-ipod-noticias

How a title gets dirified is of little importance here. What is crucially important is that the permalink doesn’t change—an issue when moving from one platform to another. The average blogger probably doesn’t care about this too much—but there are some people (myself included) who wouldn’t want all the old links to our blog posts to break, especially when it comes to maintaining that precious PageRank™ (and findability).

When I moved from Blogger to WordPress 1.5, I managed to maintain the permalinks the hard way (just shy of updating every one by hand). These days, the importer is so good, practically all you have to do is click a link and sit back. I wanted the same to be true for the permalinks.

Instructions for WordPress 2.3

  1. Download and unzip wp-maintain-blogger-permalinks-1.0.zip (v1.0)
  2. Upload the file wp-maintain-blogger-permalinks.php to your plugins directory:
    /path/to/wordpress/wp-content/plugins
  3. Activate the plugin (don’t forget!)
  4. Under Manage > Maintain Blogger Permalinks click the button that says Maintain Blogger Permalinks
  5. That’s all. You can deactivate and delete the plugin if you like.
  6. If you don’t mind your WordPress permalinks ending in .html (like Blogger does), just go to Options > Permalinks, select Custom, and enter the following:
    /%year%/%monthnum%/%postname%.html

    …and you’re done.

  7. If you’d prefer your WordPress permalinks not ending in .html, but of course want to make sure the old .html links still resolve, go to Options > Permalinks, select Custom, and enter the following:
    /%year%/%monthnum%/%postname%/

    …then add this to the top of your .htaccess file:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html$ $1/$2/$3/ [QSA,R=301,L]
    </IfModule>

    …and you’re done.

That’s it. As always, if you’ve got questions, please feel free to leave a comment.

relatedposts

49 comments

name
blog (optional)
comment

Well, am I really the first one to comment, or is this just the weird design?

Anyway, tried everything perfectly, and all I am getting is errors about unexpected [ in pragma. any help?

BTW, I guess this will help me to maintain links to my own posts, right? I mean, if I had a link to http://yuvipanda.blogspot.com/somepermalink, and I import it to wp, I get it as http://blog.yuvisense.net/samepost, right?

Any help? While I am no no-programmin-allowed guy, I am certainly a noob in PHP, so, please help:D

Yuvi, yep, you’re the first. This method is really not intended for blogspot-hosted blogs because blogspot offers no way to automatically redirect a request for an old post to a new location. So the benefit of maintaining a permalink in that case is only superficial. However, if you still want to do that, this method should work for you.

I would need more information about the error you’re getting (when it happens, the exact text, etc) to determine what might be the cause.

Thank you! Question: I have a blogger blog that has three flavors of permalink URLs - some have “.html”, some have “.php” and some have no extension. How might I modify the included script so that I can migrate to Wordpress and still maintain all the permalinks? (could I import them all with no extension then use the “resolve” trick–step 7–to work for both .html and .php urls?)

Scott, in the rewrite rules in your .htaccess file, replace the long last line in the example at the bottom of this post with:

RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)(\.html|\.php)?$ $1/$2/$3/ [QSA,R=301,L]

That should match anything that ends with .html, .php or nothing.

Hi Justin,

Thank you for these suggestions, i’m really interested on keeping the same permalinks but i’m getting this error:

Warning: Unknown modifier ‘]’ in blogger.php on line 412

for each post trying to import. Same error on WP 2.0.4 and 2.0.5, any help?

Fernando, oh shoot! You found a bug.

Unfortunately it’s because WordPress has a bug that causes it to remove backslash characters (\) inside <pre> blocks. I usually get around this by escaping the blackslash with &#92;, but it appears that I missed one in the regular expression on line 412.

If you change your updated line 412 to

preg_match("/([^\/]+)\.html$/", $postinfo[6], $matches);

… that should fix it.

Thank you for the very helpful comment, as this appears to be what was impeding Yuvi.

Justin,

I don’t know regular expressions but i found something that seemed to work too.

I changed line 412 for this and it worked:

preg_match(”/([_A-Za-z0-9-]+)\.html$/”, $postinfo[6], $matches);

Of course your solution looks better ;-)

I’m going to import it again to be sure, thank you for Suicide! ;-)

thank you for Suicide!

May not be legal in some states :)

Justin, I was all ready to run the importer with the new changes and my blogger account was moved to the new beta blogger site! Now, the login doesn’t work for the blogger import feature. Any ideas on who to ping to get the blogger import script updated to include the new blogger?

Scott, it looks like you might be up a creek…

Here’s the WordPress ticket tracking that issue: Blogger Import failing with Blogger Beta (#3063)

[…] Siguiendo las indicaciones que amablemente nos ofrecen desde Justinsomnia.org (aquí y aquí) procedemos a modificar el fichero blogger.php que se encuentra en el directorio wp-admin/import/ de tu instalación de WordPress. […]

Thanks Justin, luckily I have an early import of the site to WP that I did before the Beta Blogger fiasco. The problem is that I imported them before using this script and so many of the links are incorrect (as you’ve described, without the “the” and so on). Is there a good way to retroactively apply your script to the WP posts to correct the naming convention?

I have as an RSS feed of the posts which I can import into WP. I could do a search and replace within a text editor to change the “post_name” tag to fit the blogger naming convention (the post_name currently is in WP style). The blog is 1600 posts long so I can’t really change each title by hand.

Any suggestions are greatly appreciated!

scott, you might want to send me an email to see what we can do. There are a number of strategies I can see taking. I haven’t played with blogger beta yet, but I’m assuming you can set the archive template so that you can output the permalink url and the title for every post by month in a format that can be readily imported into php (as an array). Then we could write a little code to lookup the post in WordPress by title and update its post-slug (the permalink identifier) to what Blogger used.

I have to enter /sitename/index.php/year/month/postname in the address in order to reach the individual post page. Any ideas what I did wrong?

[…] Oh, btw, the Blogger import thingy in Wordpress works pretty good - together with these hints/and modifications here and some additional .htaccess tweaks and copying of static files, the transition was pretty fast and smooth. […]

If the importer fails with “Error on form submission. Retry or reset the importer.” then read this: http://wordpress.org/support/topic/82001

The redirect in my .htaccess file seems to have no effect, links are not being re-directed. Suggestions on where to start troubleshooting?

Ok, i’m havin some problems importing my beta blogspot blog into a wordpress one. I used This Script in PHP to export the blog, but as you can see my blog is in Spanish, so i use a lot the ñ and the accents and some of my post have very long tittles, so i’m having the problems you mention in the entry. I think i’ll wait for an official importer from wordpress or someone to release a solution

mjeppson, did you add the .html fixing rewrite rule as its own block, separate from the WordPress rewrite rules—this is important. You might want to try specifying the full URL in the rewrite, e.g.

http://www.freshdv.com/1/2/3/

sinisterff, you’re better off asking the creator of that specialized script to add the ability to maintain blogger’s permalink slugs.

[…] Note: Si vous hébergez vous-même votre blog Blogger, visitez Maintain permalinks moving from Blogger to WordPress by Justin Watt (EN). […]

I need some help with my WP permalinks. I don’t know the first thing about .htaccess and the code behind all of this permalink-stuff. So any help would be apprecaited.

I’m currently using the default WP permalink structure.
I’d like to change the structure to: /%category%/%postname%/

When I change the structure in the permalinks admin panel and I test the pages, I get what appears to be the main page of my site. (for example, the comment now box doesn’t appear, and there are other posts on the page).

Any ideas what might be causing this?

ben, hmm. You should not have to mess with the .htaccess file or anything in order to change your permalink structure. Have you tried changing it in a different way to see if that works, e.g. “Date and name based”?

/%year%/%monthnum%/%day%/%postname%/

Reading the Using Permalinks documentation, I see that:

%category% does not work correctly with some implementations of mod_rewrite in Apache versions prior to 2. If you are using Apache 1 and experience problems using %category%, either do not use %category% in your permalink structure, or refer to Schlueterica’s plugin.

Thanks for responding. I changed the permalink structure to the one you suggested:

/%year%/%monthnum%/%day%/%postname%/

but the problem remains. Take a look at GarnishBar.com and click on a post to see the result.

ben how strange. I see that WordPress is rewriting all the permalinks to the new structure, and it appears that mod_rewrite on your webserver is correctly forwarding the generated permalinks on to WordPress to determine what to serve (otherwise you’d be seeing 404 errors), but for some reason, WordPress is just returning the homepage.

In your root web directory (the one you move the index.php file into) does your .htaccess file look like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

In the very least, it looks like you’re not alone: 2.0.6 Problem with Permalinks. Perhaps try upgrading to 2.0.7?

Yup looks just like that:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Sorry ben, I’m not sure what’s going on. Could be some weird interaction between mod_rewrite and WordPress. I’d add your 2 cents to the 2.0.6 Problem with Permalinks support thread.

[…] PageRank de Google. Esto lo logré revisando algunos blogs que tuvieron el mismo problema: Maintain permalinks moving from Blogger to Wordpress y Moving from Blogger to Wordpress: Best […]

Thanks. I was stuck with an .htaccess issue moving Whizgiggle permalinks, already-indexed as YYYY/MM/DD/post-title, to simply /post-title. Turns out I was mixing my rules with WP rules. Worked as soon as I moved my block up above the WP block. It’s important to think about what I’m doing I suppose. :)

I think I’ll poke around your site a bit. Looks nice. This layout is pretty snazzy. -bill

What about Wordpress 2.2? It seems that the blogger.php file is totally new. Any help ?

Hi I’m trying to import from blogger using the inbuilt blogger import tool in 2.2. (I was mightily impressed that you helped adapt it to ensure permalinks were being kept). However the permalinks are not being accurately imported. blogger.php is now markedly different to the one you refer to on this page, and I can’t make the changes you suggest.

As an example,

http://dermod.blogspot.com/2007/07/importing-podcast-into-wordpress-from_01.html

changes to

example.com/2007/07/importing-a-podcast-into-wordpress-from-blogger-part-two.html

In many cases, unless the permalinks are short, the wordpress created permalinks are longer.

Any idea what to do? I’ve posted this question on the support forums here.

Thanks for your time

Dermod

I have made a patch to the blogger import code from Wordpress 2.2.1 that will maintain the blogger styled URI on your new WP site. Have a look at http://my.opera.com/djp/blog/2007/07/02/maintain-permalinks-moving-from-new-blogger-to-wordpress-2-0 and let me know how you get on.

Superb, David, well done, works a treat!

Just a quick question to follow up - I need to write in the .htaccess file a rewrite rule that changes requests for the old blogger archive and labels files to either the relevant archive and category pages in wordpress, or at least the index page. Google tends to use archive pages in old results.

So if someone is looking for the May 2006 archive, the structure in blogger is:

http://bonhom.ie/archive/2006_05_01_archive.html

In wordpress, the structure will be:

http://bonhom.ie/2006/05

Similarly, with categories/labels, the blogger structure is, for example with music:

http://bonhom.ie/labels/music.html

The wordpress structure will be:

http://bonhom.ie/category/music

I attempted tinkering with the .htaccess file myself but I don’t know what I’m doing and it crashed wordpress.

Any help would be greatly appreciated!

Sorted it out myself. Answer is:

RewriteRule ^labels/([^/]+).html$ category/$1/ [QSA,R,L]
RewriteRule ^archive/([0-9]{4})_([0-9]{1,2})_([0-9]{1,2})_archive.html$ $1/$2/ [QSA,R,L]

hi justin!

i am with js-kit and we have some cool widgets for blogs. i am writing to see if you would be interested in working with us to create plug-ins for wordpress for our widgets.

you can reach me at khris at js-kit.com

http://www.js-kit.com

I just wanted to say thanks for Instruction #6 on how to change your permalinks to have the html at the end and Wordpress Suicide. I tried it tonight, was able to delete my blog and reimport. Thanks so much!

I’ve significantly updated this post for WordPress 2.3 (from WordPress 2.0.4) including a new single button push utility plugin that will update all your imported Blogger posts to use their old Blogger post slugs.

Once you run the plugin you can deactivate it and delete it. It does not need to stay installed to work.

Superb plugin Justin, I’ve just applied this to our blog and the URL’s are now exactly how I wanted them (the same as blogger).

I’m actually having a problem with the RSS feed using FeedBurner at the moment though, getting a 404 error when trying to burn the feed, they seem to think this is caused by the new permalinks. Would be great if you have any ideas about how to fix this.

Thanks,
Kevin

Kevin, yeah, if you had Feedburner set up before updating your permalinks to the old Blogger slugs, FB may publish old permalinks for a while. However looking at your feed, all the entires now appear to resolve correctly.

Howdy, a couple things to make your article more visitor friendly…. well, more friendly to non-techie types. Its fair to assume many come here already wanting this specific information but some of us come just to even begin understanding how to make the switchover from Blogger to WP, so explaining the major benefit(s) of employing this action would be super valuable.

In other words, I see that it is possible but what is the downside if I don’t keep the slugs the same? What is the upside if I do?

My main concern is to create a fluid movement from people coming in from an old link and being able to get to the right area on the new site.

Is that possible?

Thanks,
Sam
ps. maybe put (updated for wp2.3) at the very, very top. Again, thanks.

is there an update for this for the new WP 2.3.2?

I believe this should work with 2.3.2… Please let me know if that’s not the case.

Justin, the plugin works fine whit wp 2.3.2 version, my blog export ok from blogger, thank you! I made a little donation to your plugin

Thanks Thanks Thanks, It’s so help full i would be lost with out this post actually i’m moving my blog from blooger to wordpress, by the way i dont want to loose my permalink and search results . i have been trying lots of method for past 2 weeeks, yours worked

I am so obliged to you , thanks thanks so much

Hi, this is my wordpress structure :
/index.php/%year%/%monthnum%/%day%/%postname%/
When i try the instructions, i obtain an Error 500 on the server, and i must delete the .htaccess file !
When i try to change my wordpress structure, Error 500 too ! Can you help me please?

Hi Robert, it sounds like your webhost may not be set up to allow .htaccess files? I would try to contact their support staff who probably have experience with configuring WP.

But looking at antivoitures.free.fr (if that’s the blog in question) suggests that the permalinks are ok.

Thanks for creating this script! This saved me tons of time I’m sure. :)

Hi! i only want to say thank you for your usefull plugin!
Really i searched over internet for long time to solve blogger to wp redirection problem, without success…..now sems work all fine!
thank you again
G. (WP 2.3.3)

THANK YOU THANK YOU! This plugin saved my sanity! It worked!

One little question– can I delete the old Blogger blog? Will this affect the redirects?