XF 1.5 Please help with SMF redirects after migration (URGENT)

TheUnderdog

New member
Greetings,

I have recently moved from SMF to Xenforo, but I have no idea how to redirect the URLs so that there are no broken links.

The old SMF forum is located at domain.com and the new Xenforo forum is located at domain.com/forum/

How am I supposed to redirect if old forum threads are in the form of index.php?topic=TOPIC-ID while the new Xenforo threads are in the form of index.php?threads/friendly-topic-name.TOPIC-ID/

Seems to me that it is not possible?

Am I missing something?
 

TheUnderdog

New member
This is what I have so far which isn't completely working:

-

RedirectMatch ^/$ /forum/

RewriteEngine On

# redirect threads
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 [R=301,L]

# catch all for everything else
RewriteRule ^.*$ /forum/ [R=301,L]

-


It is currently working like this:

domain.com/index.php?topic=123

is being redirected to

domain.com/forum/threads/123/?topic=123

but I don't want that final "?topic=123" to be added to the redirected URL.

FIRST QUESTION: How can I remove that trailing part?

Now, the second issue is that I still cannot make URL redirection for specific messages to work since it changes the # to %23 so then Xenforo won't be able to recognize %23post-123 at the end of the URL.

SECOND QUESTION: How can I fix this?

The final issue is this:

domain.com/index.php?topic=123.50

is supposed to take me to post 50 of that topic, not back to the first topic.

THIRD QUESTION: Old links to specific pages of a topic redirect to the first post of the topic. Is there a way to fix this?

Thank you.
 

Mike

XenForo developer
Staff member
In terms of removing the query string, I believe this works:
Code:
RewriteRule ^index\.php$ /forum/threads/%2/? [R=301,L]
Essentially you add a "?" at the end.

For the hash link, it looks like you need the NE flag: (https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne)
Code:
RewriteRule ^index\.php$ /forum/threads/%2/#post-%3 [R=301,L,NE]
You may need the "?" trick too but I'm not sure if this will work:
Code:
RewriteRule ^index\.php$ /forum/threads/%2/#post-%3? [R=301,L,NE]
Regarding domain.com/index.php?topic=123.50, if that's the 50th post in the thread, we don't expose a URL like that so you can really only redirect to the thread itself (or write a custom redirect handler for this).
 

TheUnderdog

New member
Hello Mike,

Neither solution worked. I wonder why?

I don't want the query string to be added at the end of the redirected URL, is there another workaround for this?

I used the NE flag as well for the second issue but it didn't do anything. That's weird, it should work.
 

TheUnderdog

New member
I am having issues with my redirects.

Here's how my htaccess file looks like:

Code:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

RewriteCond %{QUERY_STRING} (^|\?|&)board=([0-9]+)\.[0-9]+($|&)
RewriteRule ^index\.php$ /forum/forums/%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]

# catch all for everything else
RewriteRule ^.*$ /forum/? [R=301,L]
My forum is located at domain.com/forum

The above redirects domain.com to www.domain.com/forum

However, it does NOT redirect domain.com/forum to www.domain.com/forum

What am I missing?

Another question: How is it that the last RewriteRule isn't redirecting EVERY URL, including valid forum URLs, to domain.com/forum? I am glad it isn't, but I'm wondering the reason behind it. I'm not sure how it works.
 

Mike

XenForo developer
Staff member
Your XF directory has its own .htaccess file, which includes a catch all line at the end. You'd need to apply the www changing rewrite in that file as well.
 
Top