Redirection script for SMF 2.0 [Deleted]

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.
 
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 'dotheton.com' not work, but www.dotheton.com 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.
 
I found something in the old topics over here that might help. You can skip the script.

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

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]
 
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...
 
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.
 
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.
 
So I have a number of folks that have the default bookmark domain.com/forums/index.php

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

Code:
// *** Variables ***

$redir_url = 'https://www.domain.com';    // 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.
 
Does the script have this line at the end?
Code:
// 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
Code:
else redirect($redir_url . '/');

It works now.
 
Here's my rules set based on various posts here and URLs I was encountering that were not matched using Custom 404 add-in.

Moved from a subfolder https://secretprojects.co.uk/forum/ to root https://secretprojects.co.uk (so bear that in mind if adapting the rules. The only things that broke were internal links to attachments posted by users; these were message + attachment ID in the URL, the attachment IDs were not preserved.

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;
 
how would I write this if I had newforum.website.com as my new xenofroro site and website.com/oldforum as my old site
 
Top Bottom