# Topicslug with numbers gets translated into topic id?

**URL:** https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491
**Category:** Support
**Created:** [March 25, 2019, 9:51am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491 "2019-03-25T09:51:43Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![pontus.dualdecade](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pontus.dualdecade](https://meta.discourse.org/u/pontus.dualdecade)
#### Post date: [March 25, 2019, 9:51am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/1 "2019-03-25T09:51:43Z")

</div>

So, on our discourse server we use topic slugs like `123-region-2` this has been no issue until recently. Now it seems thats the discourse server, if it gets a request for example `5454-region-3` and that topic slug does not exist. It gets the topic with topic id `5454` and this creates a lot of problems.

Was there an update to this behaviour recently? We usually run `launcher rebuild` close to once a week so we have 2.3.0.beta5 right now.

Another theory might be that our 123 part in `123-region-2` is always higher than topic ids and they both have just been increasing causing no “collisions” but now that we added another region which starts of from 0 again we almost exclusively get collisions with existing topics.

Is there a way to make sure if we get `http://discourse.server.com/t/123-mytopicslug-2.json` and that topic does not exist we get a 404?

---

<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: [March 25, 2019, 10:52am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/2 "2019-03-25T10:52:40Z")

</div>

> [@pontus.dualdecade](#):
>
> Is there a way to make sure if we get `http://discourse.server.com/t/123-mytopicslug-2.json` and that topic does not exist we get a 404?

Why would you even have this form to begin with? Where is the numeric ID of the topic? The URL is malformed the way you’ve written it.

Here’s what it _should_ look like:

`https://meta.discourse.org/t/slug/112491`

Where `slug` can be literally any text imaginable, because _it doesn’t matter_. Only the numeric ID of the topic does.

---

<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: [March 25, 2019, 11:04am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/3 "2019-03-25T11:04:14Z")

</div>

Starting a title with a number is a bad idea as you describe. The problem is that the slug is ignored by Discourse and that if you start a slug with a number and that number matches a topic\_id you’ll get that topic.

These both resolve to this topic

```
https://meta.discourse.org/t/112491

https://meta.discourse.org/t/112491-degggrdff

```

You’ll need to change your convention to use titles like 'region 5454 section 3" rather than `5454-region-3`

Oh, but if the final topic id is there, then the right thing happens. Why are you removing the topic\_id?

```
https://meta.discourse.org/t/1234-topicslug-with-numbers-gets-translated-into-topic-id/112491/3

```

---

<div class="post-metadata">

### Author: ![pontus.dualdecade](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pontus.dualdecade](https://meta.discourse.org/u/pontus.dualdecade)
#### Post date: [March 25, 2019, 12:53pm UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/4 "2019-03-25T12:53:48Z")

</div>

We do this lazily, so the client predicts the topic slug. We have no way of predicting the internal discourse topic id.

So we have to get the topic solely based on the slug.

If we change the slug to be region-1-123 instead and that works I guess thats a solution. To clarify, the numbers 1 and 123 here has nothing to do with discourse and are generated elsewhere.

Or, if there is a way to get topic id by topic slug only that would be great in our case.

---

<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: [March 25, 2019, 1:39pm UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/5 "2019-03-25T13:39:41Z")

</div>

> [@pontus.dualdecade](#):
>
> We do this lazily, so the client predicts the topic slug

Right. Then you’ll need to make sure that your titles won’t start with numbers.

> [@pontus.dualdecade](#):
>
> Or, if there is a way to get topic id by topic slug only that would be great in our case.

I think you can get that from the API. Search “reverse engineer api”

---

<div class="post-metadata">

### Author: ![pontus.dualdecade](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pontus.dualdecade](https://meta.discourse.org/u/pontus.dualdecade)
#### Post date: [March 25, 2019, 1:45pm UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/6 "2019-03-25T13:45:42Z")

</div>

Nice, we only have 37k topic slugs to rename. 😃🔫

---

<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: [March 25, 2019, 3:09pm UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/7 "2019-03-25T15:09:03Z")

</div>

Renaming 37K topics could be done with a script. If you have a budget for such, post on #Marketplace or contact me directly.

Re-training your users to guess new URLs, which would seem much harder. But how did you train them to guess URLs in the first place? Are they coming from some other site that you manage?

---

<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: [March 26, 2019, 12:10am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/8 "2019-03-26T00:10:02Z")

</div>

> [@pfaffman](#):
>
> Why are you removing the topic\_id?

You kinda buried the lede here. This is the entire question: _why_ do it this broken and non-standard way?

---

<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: [March 26, 2019, 1:08am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/9 "2019-03-26T01:08:43Z")

</div>

Indeed. I got lost on this one a couple different ways.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 22, 2022, 7:01am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/10 "2022-05-22T07:01:02Z")

</div>



---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [May 22, 2022, 9:22am UTC](https://meta.discourse.org/t/topicslug-with-numbers-gets-translated-into-topic-id/112491/11 "2022-05-22T09:22:37Z")

</div>


