XF 2.1 Redirecting thread URLs

cwe

Well-known member
Manual states:
... using the XenForo redirects for vBulletin add-on, which started shipping with XenForo from version 2.0.2.
...


I've just installed XF 2.1 and I don't see this add-on. The only add-on included with the install package is named XenForo Importers 1.2.3 and it doesn't add the menu items to the options menu as described in the manual.

I've imported my old vB 3.8 forum data into a clean XF install retaining the thread IDs. The old vBSEO urls for my threads use this format:


www.domain.com/forums/f23/thread-title-1255/

I need a redirect to point them to this format:

www.domain.com/threads/thread-title.1255/

I'm not particularly concerned with redirecting any other old URLs. My server is running Apache. Would there be a simple bit of code I could add to my .htaccess that would handle redirects for the old thread URLs?
 
One of the problems is that vBSEO had the option of using a lot of different URL formats and what works for one may not work for others.

However, you might have a look at these:


Unfortunately, that tool has been archived and the original source at http://tools.geekpoint.net/xfseo/ generates a "server not found" error. You might ask @Jake Bunce or @Chris D or @ozzy47 if they know if that tool still exists anywhere else.


As an alternative, this is the .htaccess rewrite rule I used on an old vBulletin 4 forum before it was converted to Xenforo:


But note that was written to convert from old vBSEO URLs using .html links to non-vBSEO vBulletin links and you would need need to modify the Rewrite rule URL structure. And if you weren't using the .html vBSEO format, that of course won't work.

You can also try:


That will give you options for vBSEO different formats. Again, you will need to modify them to use the Xenforo format in the rewrite link.
 
Last edited:
Wow. So I read your post twice and it seems that the replacement you instructed should be doing things backwards. But maybe it's just an issue with how things are worded.

I actually tried reversing the order of the source and dest match strings from your example and of course, it did not work. I then tried your example (slightly edited) and it works. I don't understand why, per the description, but I'll take it.

I created three route filters:
Code:
Find Route:  threads/{threadtitle:string}.{threadid:digit}/
Replace with:  forums/f{forumid:digit}/{threadtitle:string}-{threadid:digit}/
That one works and captures 95% of the threads I need to capture.
Code:
Find Route:  threads/{threadtitle:string}.{threadid:digit}/page-{page:digit}
Replace with:  forums/f{forumid:digit}/{threadtitle:string}-{threadid:digit}/index{page:digit}.html
That works fine too, but I think the number of posts per page on my old forum doesn't match the new XF install, so the content on page X of a given thread on the old forum might be different from the new XF forum. I'll have to double check that so threads have the same number of pages.
Code:
Find Route:  threads/{threadtitle:string}.{threadid:digit}/post-{postid:digit}
Replace with:  forums/f{forumid:digit}/{threadtitle:string}-{threadid:digit}/#post{postid:digit}
This one does not work. Interestingly, the URLs for post ids on XF seem to have the form:
https://www.domain.com/threads/thread-title.1255/post-10348
but when visited, resolve to:
https://www.domain.com/threads/thread-title.1255/#post-10348

Oh what a difference a single dash makes.... :(
 
Last edited:
Yeah, it's quite confusing at first :)

Route filters are normally used to replace standard XenFor URL format (Find route) with and new one (Replace with).
When a requests hits the server, they are processed in reversed order.
As the rule is configured to only become active for incoming requests, it does work fine; it obviously wouldn't work for replacing XenForo URLs
though.

forums/f{forumid:digit}/{threadtitle:string}-{threadid:digit}/#post{postid:digit}
This can't work, anchors never reach the server.

Is this mechanism as efficient (or more efficient) than htaccess rewrite rules?
.htaccess wouldn't work at all without further support code in XenForo or using an intermediate redirect.
The reason is that XenForo will use the original request URI when routing, not the rewritten one.

In case of an intermediate redirect the route filter approach is definitly better (for those requests, overall it does add some overhead).

And it is simple :)
 
Last edited:
I'm guessing there is some internal processing happening allows XF to translate "/post-pid" into "/#post-pid"? Is there any way to adjust that format to remove the dash (to resolve to "/#postpid")?
 
The server will only see forums/f{forumid:digit}/{threadtitle:string}-{threadid:digit}/, the anchor part #post{postid:digit} is only processed by client - you can't access this on the server.
And as you don't have the postid on the server in this case there isn't anything that could be done.
 
Yeah, my last post was really asking if there was a way to configure the (default) anchor text that XF is generating. XF is generating anchor text that is almost identical to what I had before, just with an additional dash in it. I guess XF doesn't offer any way to configure how it formats the anchor text for posts?

Separately, I wanted to build a route filter to capture links for my tags. I tried to set one as follows:
Code:
Find Route:  tags/{tag:string}/
Replace with:  forums/tags/{tag:string}.html

but for some reason, XF insists on adding a trailing slash to the replace with field when I click save. It didn't do this when I created the second route filter listed above.
 
Last edited:
After a few headaches, I think I got it. I added:
Code:
    RewriteRule ^forums/tags/(.*)\.html$ /tags/$1/ [R=301,L]
to the stock Xenforo .htaccess file just before the first RewriteCond. I had originally placed the line after the last RewriteRule and it didn't work. Placing it before the first RewriteCond fixed it.
 
Not a huge deal, but I was hoping to redirect URLs to member profile pages. I don't see how it will be possible though.

Code:
Find Route:  members/{member:string}.{member:digit}/
Replace with:  forums/members/{member:string}/

The old URLs don't include the member ID, XF URLs do. That doesn't work and I can't think how .htaccess could do it either.
 
I was hoping to preserve the links the moderating team has posted in the private moderator's forum. Like I said, it's not a huge concern - the mods can just search for any members where a link doesn't work. I was just trying to make life easy for them.
 
A vBSEO URL format without ID is broken by design as vBSEO did not store URLs but calculated them on the fly.

So usernames Kirby and !!Kirby!! (which are disjunct) would be the same url.
I am sorry, but there isn't anything that could be done in a reliable, deterministic way.
 
Top Bottom