How to import bbPress images and links redirect 301 to Discourse?


I handled to transfer all the contents of bbPress to to Discourse “development environment”, by use bbpress.rb script.

but I have two questions that I would help with:

1: All the images appear on the Discourse with this path “/wp-content/uploads/img_644e48aedc2bf.jpg” it the same bbPress media url path , how can I import the images as well so that they move to the expected path on Discourse?

2: my bbPress default permalink were like this "", bbPress uses permalink also


in sql… my question is how can I edit bbpress.rb code so that can import old links and redirct to new Discourse links 301 without any problem later?

so, when the user tries to visit the old site

, the link is redirect 301 to the new one


can you give me a hand with these questions?

Hi there,

For 1, you will need to change the bbpress script to copy the avatars from the folder, and upload them to your Discourse instance. You can check the vbulletin import script for an idea on how that could be achieved, on line 212.

As for 2, that is actually going to be a bit more complicated since Discourse can’t access external websites’ data (like So the best way to achieve that would be to keep the same domain, and make some slight changes to the create_permalinks (line 379) function to support the postname parameter.

1 Like

If you mean in posts, then if you have download remote images to local set, Discourse will download them. There are sidekiq jobs that should run to do that.

You can look at other scripts for “Permalink”.

In short, the p=123 values should be stored in TopicCustomFields or PostCustomFields with name import_id and you can then run a script to create the permalinks.

1 Like

A few minutes ago, I activated “download remote images to local” and downloaded all the images to the local server “bbPress” . How can I activate the sidekiq jobs to let Discourse download them during import?

apologise for the inconvenience, how do I redirect all links from


I don’t think %postname%/ is the same

You just need to wait for them to finish. If you’d rather modify the script to have it handle the uploads when it runs, you can look at other scripts that do that.

You can look at other scripts that create Permalinks. vbulletin.rb has an example of permalinks.

The existing bbpress.rb handles attachments that are in the database, so you must have users who linked directly to them, or something like that? So you’d need to find them with a regex and then handle them the way that the other upload functions do. If Discourse is handling them, then you might rather just let it, as I suspect that’s going to work.

1 Like

Thank you @pfaffman @nizar9

I was able to save and transfer all the images from the old bbPress articles to Discourse by enabling the download remote images feature in the control panel

But :cry: I’m still stuck to redirect 301 old bbPress links like this


to the new link


And I can’t solve the problem through htaccess regular expression because I don’t know what’s new id for the same topic.

You cannot. There is at least one import script that will dump out data so that you can. As I said earlier, it’s possible to create Permalink redirects to solve the problem in Discourse.

Import images from bbPress to Discourse,
here is and example bbpress.rb script.
it copies the avatar images from the bbPress directory and uploads them to your Discourse instance.

# bbpress.rb

# Import bbPress avatars and update Discourse avatars
def import_avatars
  users.each do |user|
    bbpress_avatar_path = "/path/to/bbpress/avatars/#{user['avatar_filename']}"
    next unless File.exist?(bbpress_avatar_path)

    avatar_upload =
    DiscourseAvatar.create_for(user['email'], avatar_upload, override_gravatar: true)

# Call the function

Now create create_permalinks function to generate the appropriate URLs and handle the 301 redirects.

# bbpress.rb

# Create permalinks with postname parameter and handle redirects
def create_permalinks
  permalinks.each do |permalink|
    topic_id = permalink['topic_id']
    postname = extract_postname_from_permalink(permalink['url']) # Implement this function to extract postname

    topic_link = "{topic_id}/#{postname}" # Modify this line with the correct URL structure

    create_discourse_permalink(topic_id, permalink['url'], topic_link)
    create_redirect(permalink['url'], topic_link) # Implement this function to create a 301 redirect

# Call the function

The create_redirect function should add a 301 redirect from the old bbPress permalink to the new Discourse URL.
note: Replace the path according to you.

I hope it work.

1 Like

That won 't work for the uploads. Discourse gives them all new names. I hadn’t noticed that they wanted image redirects. I’ve never seen anyone ask for that.

It might work for some topics where Discourse and bbpress happen to use the same slug.