# How does permalink normalization with regex work?

**URL:** https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671
**Category:** Support
**Created:** [February 26, 2025, 5:36pm UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671 "2025-02-26T17:36:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![SubStrider](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/substrider/32/512604_2.png) [@SubStrider](https://meta.discourse.org/u/SubStrider)
#### Post date: [February 26, 2025, 5:36pm UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671/1 "2025-02-26T17:36:46Z")

</div>

I went to this setting Admin \> Permalinks \> Settings  
Which says it will apply the regex before matching the permalink.

I have an old xenforo forum URL which is  
[http://localhost/threads/xyz-abc-is-ghp.223846/](http://localhost/threads/xyz-abc-is-ghp.223846/)

And the new discourse URL is  
[http://localhost/t/xyz-abc-is-ghp/274528](http://localhost/t/xyz-abc-is-ghp/274528)

When I enter the xenforo URL in the browser without the slug like the following then it is redirecting fine but not with it.  
[http://localhost/threads/223846/](http://localhost/threads/223846/)

So I tried to use the following regex to strip the slug out but it seems to be doing nothing. Am I missing a step or is this not how its to be done?  
/^(/threads/)[^.]+.(\d+)/?$/+/\1\2

---

<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: [February 26, 2025, 9:01pm UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671/2 "2025-02-26T21:01:51Z")

</div>

You don’t need a `\2`. And you need a `\` before the period that you’ure searching for. You’ve got only one thing in parentheses. Maybe something like

```plaintext
/^(/threads/)[^.]+\.(\d+)/?$/threads/\1

```

---

<div class="post-metadata">

### Author: ![SubStrider](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/substrider/32/512604_2.png) [@SubStrider](https://meta.discourse.org/u/SubStrider)
#### Post date: [February 27, 2025, 9:57am UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671/3 "2025-02-27T09:57:48Z")

</div>

`/threads\/[^.]+\.([0-9]+)\/?/threads/\1`

this worked

---

<div class="post-metadata">

### Author: ![lilstranded](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilstranded/32/490372_2.png) [@lilstranded](https://meta.discourse.org/u/lilstranded)
#### Post date: [March 11, 2025, 6:37pm UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671/4 "2025-03-11T18:37:10Z")

</div>

> [@SubStrider](#):
>
> `/threads\/[^.]+\.([0-9]+)\/?/threads/\1`

Hey, im in the same situation and this worked for me! 🍻

But when the URL (xenforo URL) has inner pages like for example"[https://website](https://website)[.]com/threads/thread-slug/ **page-3**" then again ill get the " Oops! That page doesn’t exist or is private." error page. Any fix for this?

---

<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: [April 10, 2025, 6:37pm UTC](https://meta.discourse.org/t/how-does-permalink-normalization-with-regex-work/354671/5 "2025-04-10T18:37:26Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
