# Redirects in Discourse from Xenforo

**URL:** https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470
**Category:** Support
**Created:** [April 25, 2024, 7:41pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470 "2024-04-25T19:41:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Fajfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fajfi/32/381507_2.png) [@Fajfi](https://meta.discourse.org/u/Fajfi)
#### Post date: [April 25, 2024, 7:41pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470/1 "2024-04-25T19:41:31Z")

</div>

On my Xenforo board links look like this:

For category:  
[https://example.com/forums/category.1234/](https://example.com/forums/category.1234/)  
/forums/category-name.ID/

For post:  
[https://example.com/threads/thread-name.1234/](https://example.com/threads/thread-name.1234/)  
/threads/thread-name.ID/

Unfortunately I guess by the amount of / and . redirection does not work after addning it in the discourse panel (/admin/customize/permalinks), is there any way to repair this and create proper redirection?

---

<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: [April 25, 2024, 11:51pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470/2 "2024-04-25T23:51:43Z")

</div>

There is a permalink\_normalization site setting to help with that.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [April 25, 2024, 11:57pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470/3 "2024-04-25T23:57:53Z")

</div>

Also:

> [@Redirect old forum URLs to new Discourse URLs using permalinks](https://meta.discourse.org/t/redirect-old-forum-urls-to-new-discourse-urls-using-permalinks/20930/1):
>
> ### Permalink Normalization
> 
> > [@Redirect old forum URLs to new Discourse URLs using permalinks](https://meta.discourse.org/t/redirect-old-forum-urls-to-new-discourse-urls-using-permalinks/20930/36):
> >
> > Just wanted to circle back to this to mention a few of the gotchas that I found and perhaps leave some breadcrumbs for future travellers - because I found this hellishly difficult to debug.
> > 
> > **Escaping in the permalink normalization string**
> > 
> > The format of the permalink normalization string has two components
> > 
> > 1. the **Regular Expression** string
> > 2. the **Replacement** string
> > 
> > They appear, one immediately after the other, in the permalink normalization string like so
> > 
> > ```plaintext
> > Permalink Normalization
> > Regular Expression Replacement
> > <-------------------------><------------->
> > /(this)reallyis(intuitive)/\1reallyisn't\2
> > 
> > ```
> > 
> > Importantly, slashes are treated differently in the different parts of the same string.
> > 
> > A slash (and other regex chars) in the **Regular Expression** part of the string **must** be escaped, however, slashes do not need to be escaped in the **Replacement** part of the same string and will instead be treated literally.
> > 
> > **The Format of incoming URL strings**
> > 
> > Secondly, and this took me a while to nail down, you match the URL as a relative path description from root but you will not receive the `/` as the first part of the string.
> > 
> > For example, if the URL that your old forum uses looked like this…
> > 
> > `http://oldforum.com/chat/the-topic-title/post/d9aa09c3-19bd-4c6e-9d8d-a8f1008000a1`
> > 
> > …then the URL that your the regular expression in your permalink normalization will match against will look like this…
> > 
> > `chat/topic-title/post/d9aa09c3-19bd-4c6e-9d8d-a8f1008000a1`
> > 
> > i.e. a path description from root but without the leading `/` slash. (I _guess_ that YMMV here depending on the structure of the URLs that you are redirecting - but I don’t think so).
> > 
> > **Examples**
> > 
> > Here are some examples from my migration project
> > 
> > ```plaintext
> > CATEGORY_LINK_NORMALIZATION = '/(cat)\/(.*?)([#\?].*)?$/cat/\2'
> > POST_LINK_NORMALIZATION = '/chat\/(.*?)\/(post)\/(.+?)([#\?].*)?$/post/\3'
> > TOPIC_LINK_NORMALIZATION = '/(chat)\/(.*?)([#\?].*)?$/topic/\2'
> > 
> > ```
> > 
> > **The Process**
> > 
> > | Old URL | Permalink Normalization | URL Match Text |
> > | --- | --- | --- |
> > | [http://oldsite.com/cat/history](http://oldsite.com/cat/history) | `/(cat)\/(.*?)([#\?].*)?$/cat/\2` | `cat/history` |
> > | [http://oldsite.com/chat/topic-title/post/d9aa09c3-19bd-4c6e-9d8d-a8f1008000a1](http://oldsite.com/chat/topic-title/post/d9aa09c3-19bd-4c6e-9d8d-a8f1008000a1) | `/chat\/(.*?)\/(post)\/(.+?)([#\?].*)?$/post/\3` | `post/d9aa09c3-19bd-4c6e-9d8d-a8f1008000a1` |
> > | [http://oldsite.com/chat/mindgames-in-football](http://oldsite.com/chat/mindgames-in-football) | `/(chat)\/(.*?)([#\?].*)?$/topic/\2` | `topic/mindgames-in-football` |
> > 
> > The **Old URL** is as it sounds - the URL of the item in the old system.
> > 
> > The **permalink normalization** (recorded in the `permalink_normalizations` system setting) will grab the incoming URL (without the leading slash /) and apply the regex match. The resulting normalised URL is then used to match against the **URL Match Text** entered on the `/admin/customize/permalinks` screen.

> [@Redirect old forum URLs to new Discourse URLs using permalinks](http://meta.discourse.org/t/redirect-old-forum-urls-to-new-discourse-urls/20930):
>
> Redirecting Old Forum URLs to New Discourse URLs using permalinks If you’ve moved from other forum software to Discourse using [one of our import scripts](https://github.com/discourse/discourse/tree/main/script/import_scripts), then you probably want all your hard-earned Google search results to continue pointing to the same content. Discourse has a built-in way to handle this for you as an alternative to writing nginx rules, using the permalinks lookup table. The permalinks table allows you to set two things: a url to match, and what that url should show. There a…

---

<div class="post-metadata">

### Author: ![Fajfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fajfi/32/381507_2.png) [@Fajfi](https://meta.discourse.org/u/Fajfi)
#### Post date: [April 27, 2024, 6:12pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470/4 "2024-04-27T18:12:46Z")

</div>

Thanks!

Here’s regex for permalink normalizations for my case on XenForo:

[https://example.com/threads/thread-name.1234/](https://example.com/threads/thread-name.1234/)  
`/(threads)\/(.*?)([0-9].*)?$/threads/\3`

[https://example.com/forums/category.1234/](https://example.com/forums/category.1234/)  
`/(forums)\/(.*?)([0-9].*)?$/forums/\3`

* * *

When there’s numbers in thread-name or category use this

`/(threads)\/(.*?\.)([0-9].*)?$/threads/\3`

`/(forums)\/(.*?\.)([0-9].*)?$/forums/\3`

---

<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 27, 2024, 6:13pm UTC](https://meta.discourse.org/t/redirects-in-discourse-from-xenforo/305470/5 "2024-05-27T18:13:35Z")

</div>

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