Resource icon

Redirection script for SMF 2.0 2.2

No permission to download


OK - that works, but bottom line is if you use the same domain name for your old forum as the new one, which I expect 99% of people do, there's no way to make a redirect work anyhow.

Unless somehow there is a way to integrate your redirect script into the Xenforo index.php file to capture 'invalid' URL's and convert/redirect.

Mr. Jinx

Well-known member
Although I don't think it's 99% using the same domain, you are probably right that it is the most common setup.
I created this script just for my situation and thought it would ber nice to share it with this community. It helped me and a few other people.
Somehow nobody shared their settings when converting SMF in the same domain, but there must be people out there running this setup.

However, this can certainly work with a .htaccess rule. Do you use Apache as web server @torontotim ?
I will see if I can find something.


The script is awesome - would love to make it work somehow, or as you say try .htaccess. I am using Apache, on Debian 10 but at the moment I'm struggling a bit with the domain. Something is wrong somewhere, making '' not work, but does work. My A/AAAA records are fine etc.

Xenforo also seems to put its own .htaccess file in the forum root directory. I need to correct some config issues on my end as I installed the forum in /forum but I've ended up with my domain root as being /forum, so the site appears to be in the root of the domain, not in the /forum directory. Long story.

If there was a way to incorporate your mapping script into .htaccess or the Xenforo index.php, that would be ideal - and I'd pay for the service happily. After 12 years of SMF, we have thousands of links in the world pointing to the old forum.

Mr. Jinx

Well-known member
I found something in the old topics over here that might help. You can skip the script.

Assuming you have XF running in, exactly the same als your old SMF forum.
Open /forum/.htaccess (the one that came with XF).

After RewriteEngine On add:
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]


Mine is installed in /forum, but the domain root is pointed at /forum so the URL's actually don't include /forum in them.

It looks like I could remove the /forum from the rewrite rules and it might work...


Active member
I did my SMF 2.0 -> Xenforo redirects using nginx rewrites, with Siropu's Custom 404 addon being useful for finding URLs that weren't being handled correctly. If anyone is interested I can post. Nginx is waaaay faster than Apache.

Mr. Jinx

Well-known member
Sure, please share for those that are using Nginx.

ps: nginx being faster, depends on how you configure things. My site has been running on Nginx for years without problems. But at some point I moved it to a server running Apache which has been tuned by experts. This made my site load 2x faster. So it all depends on configuration and caching.


Active member
So I have a number of folks that have the default bookmark

With your redirect script, I have the settings as this:

// *** Variables ***

$redir_url = '';    // URL of your new forum, without trailing slash
$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 = 2;                                    // 0 = testing / 1 = temp redirect / 2 = perm redirect
All the redirects work, but not the index.php in forums directory.

Would anyone have a suggestion for correcting this? Is there a way to see if the are trying to trigger the index.php for the redirect do that, but if they come with no $ argument they just get redirects to the root "redir_url"


I'm not using 'friendly URLs' and have index.php? in my links. Just add 'index.php?' and remove the '/' from the redirect construction.

// Redirect boards: smf/index.php?board=5.0 >>> /xenforo/forums/5/
if (isset($url_board)) {
$ids = explode(".", $url_board);
redirect($redir_url . '/index.php?' . $forums . '/' . clean($ids[0]) . '/');

// Redirect a specific message: smf/index.php?msg=123 >>> /xenforo/posts/123/
else if (isset($url_msg)) {
redirect($redir_url . '/index.php?' . $posts . '/' . clean($url_msg) . '/');

// Redirect a specific message in a topic: smf/index.php?topic=10.msg123 >>> /xenforo/posts/123/
// and keep pagination (the hard part): smf/index.php?topic=10.110 >>> /xenforo/threads/10/page-12
else if (isset($url_topic)) {
$ids = explode(".", $url_topic);
if (substr( $ids[1], 0, 3 ) === "msg")
redirect($redir_url . '/index.php?' . $posts . '/' . clean($ids[1]) . '/');
else {
$page = floor((clean($ids[1]) / $threads_count)) + 1;
redirect($redir_url . '/index.php?' . $threads . '/' . clean($ids[0]) . '/' . ($page == 1 ? '' : 'page-' . $page));

// Redirect profiles: smf/index.php?action=profile;u=123 >>> /xenforo/members/123/
else if ((isset($url_action)) && (substr($url_action,0,10) === "profile;u=")) {
redirect($redir_url . '/index.php?' . $members . '/' . clean($url_action) . '/');

// If nothing matches, redirect to the default url
else redirect($redir_url);


I made sure my Xenforo setup matched the 20 posts per page as my SMF, and so far every test I've thrown at it works. Just confirmed member ID's etc.

My priority was topic links, as I have thousands of the old links posted both in my forum and on many other sites directing traffic to the forum, so it was critical these work.

For anyone doing this - a key is to install your new Xenforo forum in a different directory than your old SMF forum. My XF is in the root of my domain's public_html. My SMF was in /forum - which is now where the redirect index.php resides.

Xenforo could be in /f, or /forums, /community or whatever else you want so long as it is different from your old SMF installation, so the old URL's hit the modified redirect index.php in your old folder.


Active member
Does the script have this line at the end?
// If nothing matches, redirect to the default url
else redirect($redir_url . '/' . $forums . '/');
If I go to index.php, it does redirect to /forums/ instead of the root.

I just edited the line to
else redirect($redir_url . '/');
It works now.