Best practices for URL forwarding/rewriting from a previous (non-Discourse) system

In the meantime a search page has been implemented:

https://meta.discourse.org/search?q=thread+title

I use this method to redirect from MyBB to Discourse, via a banner in the showthread template:

<div style="background: yellow; padding: 3em; color: red; font-weight: bold">
 This thread was migrated to
     <a href="http://newdomain.com/search?q={$thread['subject']}">the new forum</a>.
 Please <a href="http://newdomain.com/t/welcome-to-discourse/8">transfer your username</a>
     (if you haven't done so already) then reply there.
</div>

This is a very clever idea. To create such a mapping between post IDs, you only need to add one line of Ruby code to the MyBB importer.

You now have two options:

  1. Use a web server, e.g. nginx, to do the redirects. Then you need to format the output into something ngix will understand:

    map $uri $uri_new {
    default>$uri;
    
    /...?post=8 /t/54/1;  # old post_id -> /t/topic_id/post_num
    /...?post=157 /t/73/10;
    ...
    }
    
    # do the maping - http://wiki.nginx.org/HttpMapModule
    rewrite ^ $uri_new permanent;
    

    This is what I’ve done for my MyBB forum.

  2. Keep the old forum (or a portion of it) running. It will supply the thread/post ID as a (PHP) variable, so you’ll be able to redirect even threads that don’t have an ID in their URL. What you minimalistically need to keep running is a mapping between the thread title and the thread id, so you can map from that to the Discourse topic_id and post_num.

See also the redirecting howto. Post #21 is my nginx map method.

2 Likes