Resource icon

Redirection script for SMF 2.0 2.2

No permission to download
Compatible XF 2.x versions
2.0, 2.1
Visible branding
No
Redirect rules for SMF 2.0 (Apache and Nginx).

Option 1 - Using .htaccess

There are a few things for .htaccess to work correctly:
  • SMF 2.0 was using normal URLs, like "https://www.domain.com/smf/index.php?board=5.0"
  • During the import to Xenforo, you choose to retain ID's
Open your .htaccess file.
After RewriteEngine On add:
Code:
RewriteCond %{QUERY_STRING} (^|\?|&)board=([0-9]+)\.[0-9]+($|&)
RewriteRule ^index\.php$ /forum/forums/%2/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?|&)topic=([0-9]+)\.[0-9]+($|&)
RewriteRule ^index\.php$ /forum/threads/%2/? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)topic=([0-9]+).msg([0-9]+)($|&)
RewriteRule ^index\.php$ /forum/threads/%2/#post-%3? [NE,R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)PHPSESSID=(.*);topic=([0-9]+)\.[0-9]+($|&)
RewriteRule ^index\.php$ /forum/threads/%3/? [NE,R=301,L]
Option 2 - Using Nginx Rewrites

The follow rules will redirect from yourdomain.com/forum/ to yourdomain.com/

Code:
        # rewrite rules to redirect SMF URLs
        # Message redirects
        # matching /forum/index.php/topic,101126.msg3826887.html
        rewrite ^/forum/index\.php/topic,[0-9]+\.msg([0-9]+)/?(?:wap2|topicseen)?\.html /posts/$1/ permanent;
        # matching /forum/index.php?topic=101126.msg3826887
        if ($arg_topic ~ [0-9]+\.msg([0-9]+)$) {
                set $postid $1;
                rewrite ^/forum/index\.php /posts/$postid/? permanent;
        }
        # matching /forum/index.php?msg=3826887
        if ($arg_msg ~ "^([0-9]+)(?:;wap2|$)") {
                set $postid $1;
                rewrite ^/forum/index\.php /forum/posts/$postid/? permanent;
        }
        # Thread / Topic redirects
        # matching /forum/index.php/topic,101523.25.html
        rewrite ^/forum/index\.php/topic,([0-9]+)\.[0-9]+/?(?:wap2|wap|nowap|all|prev|prev_next|prev_next,prev|prev_next,next|topicseen|page2)?\.html /threads/$1/ permanent;
        # matching /forum/index.php%3Ftopic%3D96737.0
        # http://stackoverflow.com/questions/20470191/external-links-url-encoding-leads-to-3f-and-3d-on-nginx-server
        rewrite ^/forum/index\.php\?topic=([0-9]+)\.[0-9]+ /threads/$1/ permanent;
        # matching /forum/index.php?topic=65856.0
        if ($arg_topic ~ "^([0-9]+)\.[0-9]+(?:;wap2|$)") {
                set $threadid $1;
                rewrite ^/forum/index\.php /threads/$threadid/? permanent;
        }
        # Boards redirects
        # matching /forum/index.php/board,13.0.html
        rewrite ^/forum/index\.php/board,([0-9]+)\.[0-9]+\.html /forums/$1/ permanent;
        # matching  /forum/index.php%3Fboard%3D3.0
        rewrite ^/forum/index\.php\?board=([0-9]+)\.[0-9]+ /forums/$1/ permanent;
        # matching /forum/index.php?board=13
        if ($arg_board ~ "^([0-9]+)(?:;wap2|$)") {
                set $boardid $1;
                rewrite ^/forum/index\.php$ /forums/$boardid/? permanent;
        }
        # matching /memberlist.php?mode=viewprofile&u=2745
        rewrite ^/memberlist\.php$ /members/$arg_u/? permanent;
        # Redirect old forum homepage
        rewrite ^/forum/index.php$ /forums/? permanent;
        rewrite ^/forum/ /forums/? permanent;
        # Redirect avatar folder (Friendly URLs bug)
        rewrite ^/account/avatar /index.php?account/avatar;
        # Redirect RSS feed location
        rewrite ^/forums/-/index.rss /index.php?forums/-/index.rss;
Thanks @Overscan for providing this example.

Option 3 - PHP Script

You can also use a script to redirect SMF to XF. Works with Apache and Nginx.
This script also handles thread page redirects, which the .htaccess / nginx option does not have! This is because it needs a bit of calculation.

There are a few things for the script to work correctly:
  • SMF 2.0 was using normal URLs, like "https://www.domain.com/smf/index.php?board=5.0"
  • During the import to Xenforo, you choose to retain ID's
  • Both forums are installed in separate directories (or domains)
Configuration:

Download the script and modify to your needs.
Put it in the original location of your old SMF forum, overwriting the original index.php file.

You will need to change these variables in the script:

Code:
// *** Variables ***

$redir_url = 'https://www.yourdomain.com';    // URL of your new forum, without trailing slash
$friendly_url = '1';                        // 0 = Don't use XF friendly URL's / 1 = use XF friendly URL's
$forums = 'forums';                            // Default path to index (only change this if you are using route filters)
$threads = 'threads';                        // Default path to topic (only change this if you are using route filters)
$posts = 'posts';                            // Default path to posts (only change this if you are using route filters)
$members = 'members';                        // Default path to members (only change this if you are using route filters)
$threads_count = 20;                        // Make sure the number of messages per page is the same for SMF and XenForo.
$mode = 0;                                    // 0 = testing / 1 = temp redirect / 2 = perm redirect
Note 1: If you installed Xenforo in a subdirectory, you can use something like $redir_url = 'https://www.yourdomain.com/subdir';

Note 2: Make sure you use the same value for the number of messages per page for both forums.
So, if SMF was setup for 10 messages per page, you should do the same for Xenforo (Setup > Options > Threads > Discussions per page) and modify $threads_count to 10. This way you can also redirect thread pages correctly!

Examples of the redirections this script handles:
  • Redirect boards:
    https://www.yourdomain.com/smf/index.php?board=5.0 >>> /xenforo/forums/5/

  • Redirect a specific message:
    https://www.yourdomain.com/smf/index.php?msg=123 >>> /xenforo/posts/123/

  • Redirect a specific message in a topic:
    https://www.yourdomain.com/smf/index.php?topic=10.msg123 >>> /xenforo/posts/123

  • Redirect to a specific page:
    https://www.yourdomain.com/smf/index.php?topic=10.110 >>> /xenforo/threads/10/page-12

  • Redirect profiles:
    https://www.yourdomain.com/smf/index.php?action=profile;u=123 >>> /xenforo/members/123/

  • If nothing matches, it will redirect to your default forum URL.
Author
Mr. Jinx
Downloads
25
Views
717
First release
Last update
Rating
5.00 star(s) 2 ratings

More resources from Mr. Jinx

Latest updates

  1. SMF Nginx rewrite rules

    Added Nginx rewrite rules. Thanks @Overscan for providing this example.
  2. [2.2] Update

    Added XF friendly url's option Index.php is now properly redirected to root
  3. SMF .htaccess

    Added .htaccess redirect rules

Latest reviews

Product does exactly as advertised. Ensure you read the clear instructions for getting it to redirect your SMF forum. The support for the product has been excellent, and friendly as well - which is a huge plus for a free addon.
It works, is flexible, and it works. Easy to configure, can work with or without friendly URL's. Only trick is I think your new forum should be installed in a different subdirectory than your old SMF forum.

Naturally easy if you're installing on the same server, but something to remember if you're installing on a new server from scratch.

This way the SMF redirect script can live in the domain.com/forum or whatever folder your SMF was in, and it will take people to domain.com/community, domain.com/f, or whatever directory you choose to put Xenforo into. I put mine in the root of my domain.
Top