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

79 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?

just to clarify, this is only keeping the post title/slug and not the actual URL set up?

Well, Cole, it depends. In the early days of Blogger, before Blogspot, people used it to publish to their own webspace. So if you still own the domain at that webspace, and you want to move from an ftp-hosted Blogger blog to a WordPress-powered blog, then yes, this would help you to maintain the very same permalinks.

If however you’ve been using Blogger with a blogspot.com subdomain, then this will only keep the post slug the same, which doesn’t really buy you much.

Thanks, Justin. I was just confused because in the example you use year/month/name but my Blogger (via FTP) has a set up of year_month_date_archive.html#postslug I am looking for a way to avoid broken links and easily redirect visitors to the new location - would this do the trick then?

Cole, technically, this:
year_month_date_archive.html#postslug
is not a “true” permalink, it day archive with a link target. I’m sure there’s a way to maintain those style “links” but it’d probably take a lot of effort and some javascript hacking, etc etc.

hi
really thanks for your plugin :D

is there anu solution for chinese blog? because when i use /%year%/%monthnum%/%postname%/ this custom setting,
my postname(which is title),will become a lengthy numerics

Xiawa, do you have an example of a Blogger permalink before and a “numeric” WordPress permalink after?

I know WP coverts Unicode characters it doesn’t understand to URL entities like Wikipedia does, but I’m not sure how Blogger treats non-ascii/latin Unicode characters in permalinks.

Thanks very much for the plugin! It’s exactly what I was looking for.

Do I follow these steps before or after importing my blogger blog?

Also (sorry for the double post), this also works for blogspot hosted blogs which have their own domain?

Dan, I didn’t realize blogspot blogs could have their own domain, but if so, then yes, this should work. And you should run this after you import into WordPress. If you run into problems, feel free to leave a comment.

thanks a lot for this great tip! i have finally moved my blogger account into wordpress platform including SEO points hopefully, it worked perfectly from my vertito.blogspot.com blogger account

nice ! keep it up!

Does it still work with Wordpress 2.6 ?

After reading dozens of websites which didn’t give me what I needed, I found your “suicide” script and your permlink instructions. I need to add that I had to export my posts table and perform “edit…replace” to remove all traces of myblog.blogspot.com over to the new domain root. Now, all my links and references to posts are working properly. Great job. Thank you so much. I owe you big time!

Hi,
I was psyched when I found this plugin but then I realized that it may not be applicable to me. I have been publishing on blogger and not my own domain (hence my URL contains blogspot)… My plan is to transfer to wordpress and publish to my own domain. But I think your tool wouldn’t help me since it seems to apply only to the part of the permalink following the domain name… right?

Is the only way to keep my links available to readers by leaving my blogspot blog up?

I think I’m making sense. Please let me know.

Thanks,
Stacy

Can I use this tool if i want to use wordpress permalinks like http://www.example.com/%postname%/

Can i use this, will this protect blogger links ??

I too am publishing on Blog*Spot, and am wondering how to perform the move. My circumstances are pretty much identical to Stacy’s above.

Hi there, seems I found a place where maybe I cant get a bit orientated. I am having a problem, I have Wordpress 2.7 and the only way my blog permalink structure works is with the index.php part (which I didnt have on Blogger). Ex. /index.php/%year%/%monthnum%/%postname%.html

How do I avoid using index.php? I am unable to access .htaccess file because my hosting provider doesnt supports it.

Any ideas?

Thanks for your help!

Fernando, it might be a requirement of your webhost to leave the index.php in the permalinks. I would check with them. There’s lots of helpful information on Using Permalinks.

Does this still apply for migrating to Wordpress 2.7?

Justin, when I tried to install the plugin, I got the following message:

“Incompatible archive: PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature.”

Any advice?

Thanks.

Dave, I dunno, haven’t tried. Let me know if it works for you.

Mary, sounds like something is wrong with WordPress’s ability to unzip a zip file. I don’t know why that would be a problem here.

I can’t get this the plugin to work for wordpress 2.7

This worked fine on WP 2.7 for me. Note that the Maintain Blogger Permalinks link is under Tools in 2.7. Thanks!

Hi Justin: maybe you can help, I imported 248 posts into the wordpress self hosted site i have from the former blogger site (http://PoliticolNews.blogspot.com site and everything went okay. I closed down the old blogger site, now the links to the old posts are going nowhere. New site is: politicolnews.com

How can I change the links on the current site, which I have set to % postname% - so that all those old blogger posts -point to my new site’s posts where they are located now?

Don’t want to have to rewrite all 248 articles for the links I have lost. Any ideas? hosted with hostgator, I am not techie so have to get someone to do changes in cpanel. thanks. Teri

teri, i don’t believe there’s anyway to have blogspot.com redirect to your new location on wordpress.

hey there! So I’m using this, but am super sad it’s not working for 2.7. I just realized a ton of my incoming links aren’t getting converted.

Can I nudge you to try to update it to work for us? Pretty pleeease? :) :)

here’s an example of what’s NOT working, if this helps:

original link: http://willotoons.com/blog/2004/11/whole-new-look-on-life-my-lasik-story.php

new location: http://willotoons.com/blog/2004/11/a-whole-new-look-on-life-my-lasik-story/

seems blogger not using “a” in their permalink title is what’s throwing it off?

halp!

willo, i’m not sure if anything has changed as far as the wordpress blogger importer in 2.7, but in previous versions, they saved the original blogger permalink in a custom field called “blogger_permalink”. check one of your imported posts and see if you have this in the custom fields. if you do, then the plugin, should work. if not, you might be out of luck…

Hi! Awesome plugin:) I’m getting this problem with SOME (most of the post came out great) posts: mistmatching month!

Example:
/2009/02/ciudadania-espanola.html WP
/2009/01/ciudadania-espanola.html BLOGGER

What do you think it coul be the solution? I’m guessin ti has somehting to do with those post that are saved as drafts and then published.

Juan, that’s truly odd. I’m not sure how WP could have gotten the date so wrong—perhaps it has something to do with timezones and misinterpreting GMT?