Wordpress urls to Xenforo urls - Redirect via htaccess

146 Views Asked by At

I need to redirect all my old urls to xenforo after a wp migration, i have do it but is not working.

When it redirecting the old urls to my new xenforo it causes an error of "not found" because all the urls of xenforo have numbers or ids at the end of the urls.

wp old urls:

https://www.example.com/posts/my-new-urls-for-me/

xenforo new urls:

https://www.example.com/threads/my-new-urls-for-me.1824/

I need some help to correctly redirect without errors.

1

There are 1 best solutions below

1
On BEST ANSWER

XenForo URLs rely on the numeric ID at the end of the URL.

So in your example, https://www.example.com/threads/my-new-urls-for-me.1824/ ... it is the 1824 which is significant.

The my-new-urls-for-me part is irrelevant, you can literally have https://www.example.com/threads/any-thing-you-like-in-this-part.1824/ and it will still redirect to the same thread, so long as the numeric part at the end is in tact.

More specifically, you can also do https://www.example.com/threads/1824/ with just the numeric part and it will still work.

What you cannot do is rely on the text part - not without custom coding.

To redirect from a WordPress URL to a XenForo URL, you need to know:

  1. the original WordPress slug (the my-new-urls-for-me part)
  2. the corresponding XenForo thread id that it was moved to (the 1824 part)

Then redirection becomes a simple matter of matching that slug and then redirecting to a thread with that id.

If you didn't do that at the time of migration, you'll need to do it manually now - generate a table of slugs and thread ids and use that as a lookup by your redirection script.

Unless there are no more than a few dozen pages that were migrated, I suggest not trying to do it with .htaccess alone, but instead using a database table and write a simple script which does the redirection by matching the incoming slug, locating that entry in the table, retrieving the corresponding thread ID in XenForo and then redirecting to the thread with that ID.