XF 2.1 Help with rewrites from vB to XF2.1

vicos

Member
Just finished our upgrade from vb 4.2.3-->XF1.5-->XF2.1

During import, I had it keep the Content IDs the same, in addition to the archive log.

When I got to 2.1 I tested the XF Redirect for vB AddOn. It wasn't working. Thought it might be since we were using SEO friendly links in vB.

Anyway, I removed that and just added some rewrites to .htaccess

Code:
# redirects for vB4.2. Content IDs are the same.
RewriteRule ^threads/([0-9]+)-.*$ /threads/$1/ [R=301,L]
RewriteRule ^forums/([0-9]+)-.*$ /forums/$1/ [R=301,L]
RewriteRule ^members/([0-9]+)-.*$ /members/$1/ [R=301,L]
RewriteRule ^external\.php\.*$ /forums/-/index\.rss [R=301,L]
# END

Works great, EXCEPT when someone creates a new thread where the title begins with a numeric [0-9], it return an error message when trying to redirect the user to the new thread. The thread is actually created though.

Here are some sample URLs:

vB LINK: https://testforum.mysite.com/threads/264103-new-years-resolutions

XF LINK: https://testforum.mysite.com/threads/new-years-resolutions.264103/

What the URL looks like when title begins [0-9+]:

Appreciate any assistance on this one.

P.S. Here's the complete rewrite in .htaccess so you have the whole picture:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        # DSN: redirects for vB4.2. Content IDs are the same.
        RewriteRule ^threads/([0-9]+)-.*$ /threads/$1/ [R=301,L]
        RewriteRule ^forums/([0-9]+)-.*$ /forums/$1/ [R=301,L]
        RewriteRule ^members/([0-9]+)-.*$ /members/$1/ [R=301,L]
        RewriteRule ^external\.php\.*$ /forums/-/index\.rss [R=301,L]
        # END

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>
 
Last edited:
You can probably change your .* to [^.]*, though that may need modifications -- you don't want to match if there's a dot in the URL after the number, as that would indicate it's an XF-style URL.
 
It looks like adding:

Code:
RewriteCond %{REQUEST_FILENAME} ^threads/([0-9]+)-.*!(\.[0-9]+)$

is allowing it to work on the test board. I need to do some more thorough testing.

---

Spoke too soon. It fixes post a new thread starting with a digit but breaks the vB pattern matching.
 
You can probably change your .* to [^.]*, though that may need modifications -- you don't want to match if there's a dot in the URL after the number, as that would indicate it's an XF-style URL.
Seems to be working. Thanks for the feedback! I use regex so infrequently that I never master it.
 
Top Bottom