Remapping old imported forum permalinks to posts and topics?

Continuing the discussion from Not able to create a permalink with forums/* address:

IPB has topic links like:

https://host/{slug}-{topic-id}t/

That’s done.

There are also post links like

 https://host/{slug}-{TOPIC-ID}t/?do=findComment&comment={post-id}

and

https://host/{slug}-{TOPIC-ID}t/#comment-{post-id}

Last I checked, it didn’t seem possible to make permalinks like the latter. I haven’t tried the former, but I’m thinking that won’t work either. My current solution is to use Nginx rewrite rules to just remove the comment stuff so that those links will just fall back to the topic (rather than the post).

Am I missing something?

2 Likes

Remapping permalinks to anything other than the topic will be quite difficult. I would not even attempt it.

Here’s the crux of it: “list of topic IDs” is usually a reasonably small list, but “list of post IDs” is enormous. You may have 10k topics but you’ll probably have 50k, 100k, even 500k posts.

Remember in discourse Topic IDs are unique, that is to say:

http://discourse.example.com/t/topic-alpha/1234

This is “topic 1234”

But Post IDs in public URLs are not unique, meaning:

http://discourse.example.com/t/topic-alpha/1234/3
http://discourse.example.com/t/topic-beta/4567/3

These are both “post number 3” in each topic…

3 Likes

Excellent. That means my Nginx remapping is the way to go.

I think it’s more like 2.3M. :slight_smile:

3 Likes

There is an internally unique ID for each post in Discourse but I don’t even know how you’d get to it. And at minimum you would need a 2.3M row table mapping each “old forum” post ID to the “new forum” Discourse internal post ID.

Good news: most public links are to topics, not deep links to posts anyway. So it’s a small number of links that will be affected, usually.

I’ve got the mapping from the old post-ids to the Discourse post-ids figured out, and use it to re-write IPB quotes to [quote="#username, post:#{postnum}, topic:#topicid}"], making those quotes appear like native Discourse quotes.

If there were a way to get Discourse would throw away the cruft after the topic URLs (e.g., allow a .* after the permalink), then I wouldn’t need to fuss with Nginx. Right now, links to topics work, but any link in the wild to a topic will 404. It shouldn’t be too hard to write the Nginx rule to drop the post-id part of the URLs, though.

1 Like

You are looking for permalink normalizations. I’m using them in the phpBB3 importer too.

https://github.com/discourse/discourse/blob/master/script/import_scripts/phpbb3/importers/permalink_importer.rb#L3-L4

4 Likes

Thanks, @gerhard. That’s very helpful. I have just learned that IPB has (at least?) two url schemes,so your code should make it easier to parameterize them. I don’t think I could have made sense of your code in August when I started writing importers, but now that I know Ruby, I can see that it’s pretty great! :slight_smile:

1 Like

OH! Now I see that permalink normalizations do exactly what I need. Thanks.

I also see that in the future, when I write an importer, it will be based on your phpbb3 importer.

4 Likes