# Remapping old imported forum permalinks to posts and topics?

**URL:** <https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107>\
**Category:** Development\
**Created:** [October 27, 2016, 4:20pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107 "2016-10-27T16:20:01Z")\
**Posts on this page:** 8\
**Page:** 1

## AI-generated summary

The discussion focuses on remapping old IPB forum permalinks to Discourse topics and posts. [pfaffman](/t/-/52107/1) notes that while topic links work, post links containing comment IDs do not, currently requiring Nginx rewrite rules to strip the post-specific suffixes so they redirect to the topic. [codinghorror](/t/-/52107/2) advises against attempting deep post remapping, explaining that public post IDs are not unique (e.g., post #3 exists in multiple topics) and the volume of posts (potentially 2.3 million) makes maintaining a mapping table difficult. He notes that most legacy links are likely to topics anyway. [pfaffman](/t/-/52107/5) confirms they have the ID mapping but are still using Nginx to handle URL cruft. [gerhard](/t/-/52107/6) suggests using Discourse's **permalink normalizations**, a feature used in the phpBB3 importer, which allows the system to ignore trailing URL parameters. [pfaffman](/t/-/52107/8) realizes this feature solves the problem perfectly and plans to base future importers on [gerhard](/t/-/52107/6)'s implementation.

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [October 27, 2016, 4:20pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/1 "2016-10-27T16:20:01Z")

</div>

Continuing the discussion from [Not able to create a permalink with forums/\* address](https://meta.discourse.org/t/not-able-to-create-a-permalink-with-forums-address/52100/5):

> [@Not able to create a permalink with forums/\* address](https://meta.discourse.org/t/not-able-to-create-a-permalink-with-forums-address/52100/5):
>
> Actually a permalink with a/b/c works, and one with c/xyz also works. Gotta do some digging on this later.

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?

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [October 27, 2016, 11:30pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/2 "2016-10-27T23:30:40Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [October 27, 2016, 11:35pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/3 "2016-10-27T23:35:49Z")

</div>

> [@codinghorror](#):
>
> Remapping permalinks to anything other than the topic will be quite difficult. I would not even attempt it.

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

> [@codinghorror](#):
>
> You may have 10k topics but you’ll probably have 50k, 100k, even 500k posts.

I think it’s more like 2.3M. 🙂

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [October 27, 2016, 11:37pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/4 "2016-10-27T23:37:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [October 27, 2016, 11:53pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/5 "2016-10-27T23:53:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [October 30, 2016, 2:51pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/6 "2016-10-30T14:51:15Z")

</div>

> [@pfaffman](#):
>
> If there were a way to get Discourse would throw away the cruft after the topic URLs (e.g., allow a .\* after the permalink)

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

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

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [October 30, 2016, 4:26pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/7 "2016-10-30T16:26:26Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [October 31, 2016, 5:40pm UTC](https://meta.discourse.org/t/remapping-old-imported-forum-permalinks-to-posts-and-topics/52107/8 "2016-10-31T17:40:55Z")

</div>

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.
