1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.1 vB3.7/XF conversion: htaccess rules to redirect old traffic

Discussion in 'Installation, Upgrade, and Import Support' started by Rudy, Nov 12, 2012.

  1. Rudy

    Rudy Well-Known Member

    I have seen the redirection scripts here, but feel this is better served in htaccess (especially since we can keep our old IDs). I have searched the forums and have not seen a definitive set of rules to convert incoming traffic from vB3.7 URLs over to XenForo. Since I will now have the forum on a subdomain, it makes more sense to rewrite the URLs in Apache vs. PHP.

    Based on the redirection scripts (including the one for the /archive/ version of the forums), I have looked at a redirect rule similar to this:

    RewriteRule ^forums/showthread.php?t=([0-9]+).*$ http://forums.oursite.com/threads/$1 [R=301]
    I don't care if "showthread" indicates the correct page or not (so really, I'd just like to get visitors to the correct thread), but I will have redirect rules in place for attachments, threads, posts, members, print page, and archive site. Just want to see if I've got the syntax correct; I can do the other lines easily. (I don't yet have the forum upgraded so I can check it out.)

    Pretty sure I'm on the right track here. Ultimately I'll post the completed lines here for reference.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The query string has to be checked in a cond, like so:

    RewriteCond %{QUERY_STRING} ^t=([0-9]+)(&|$)
    RewriteRule ^forums/showthread\.php$ http://forums.oursite.com/threads/%1? [R=301,L]
    This would go into a .htaccess file in your web root, assuming the "forums" directory no longer exists.
  3. Rudy

    Rudy Well-Known Member

    Ah OK, I wasn't sure if I needed to check it in RewriteCond like that as I'd seen other redirects without it. And correct-- /forums won't exist once the conversion is complete. Let me run with that and I'll see how it goes. Thanks!
  4. Rudy

    Rudy Well-Known Member

    It occurred to me a few moments ago that yes, I needed to check RewriteCond since I'm matching on a query string. (Three hours' sleep will do that to a person. :D ) In just a URL (as I use on a shopping catalog system I wrote), RewriteRule works fine since it is matching only on URL.

    Here's what I've come up with. It takes care of the six URLs with query strings pointing to vB's specific files, two for the archives (which use "friendly" URLs and not query strings), and two generic redirects for the forum's index pages. I can't think of any other URLs I need to cover which may be indexed in the search engines or in URL shorteners or sharing systems like bit.ly or AddThis--these should cover most of them.

    # Rewrites URLs for the common forum files
    RewriteCond %{QUERY_STRING} ^attachmentid=([0-9]+)(&|$)
    RewriteRule ^forums/attachment\.php$ http://forums.oursite.com/attachments/%1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^f=([0-9]+)(&|$)
    RewriteRule ^forums/forumdisplay\.php$ http://forums.oursite.com/forums/%1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^u=([0-9]+)(&|$)
    RewriteRule ^forums/member\.php$ http://forums.oursite.com/members/%1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^t=([0-9]+)(&|$)
    RewriteRule ^forums/printthread\.php$ http://forums.oursite.com/threads/%1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^p=([0-9]+)(&|$)
    RewriteRule ^forums/showpost\.php$ http://forums.oursite.com/posts/%1? [R=301,L]
    RewriteCond %{QUERY_STRING} ^t=([0-9]+)(&|$)
    RewriteRule ^forums/showthread\.php$ http://forums.oursite.com/threads/%1? [R=301,L]
    # Rewrites the archive URLs
    RewriteRule ^forums/archive/index\.php/t-([0-9]+)\.html$ http://forums.oursite.com/threads/$1 [R=301,L]
    RewriteRule ^forums/archive/index\.php/f-([0-9]+)\.html$ http://forums.oursite.com/forums/$1 [R=301,L]
    # Permanent redirects for the forum main pages
    RedirectPermanent http://www.oursite.com/forums/archive/index.php http://forums.oursite.com/index.php
    RedirectPermanent http://www.oursite.com/forums/index.php http://forums.oursite.com/index.php
    Jake Bunce likes this.

Share This Page