PDA

View Full Version : Miscellaneous Hacks - phpBB2 Thread URL Redirection Script


bbcentral
01-31-2007, 10:00 PM
This is a very simple script I wrote after I converted two forums from phpBB2 to vBulletin.

The problem was that there were dozens of pages across the web linking to particular phpBB2 threads, ie:
http://www.website.com/forum/viewtopic.php?t=1234

Of course now those links are dead, as the correct URL would be:
http://www.website.com/forum/showthread.php?t=2345

My simple script is just one single file that you upload to your forum root folder. It doesn't modify any code, doesn't require any installation, and zero configuration is required (it uses the includes/config.php to get the database settings.

If someone clicks on a link to viewtopic.php (either pointing to a thread or a post), then it will link to that same thread at showthread.php.

Installation Instructions
Upload viewtopic.php to your vBulletin root folder, eg /forum/

Working demo
Thread name "The Apogee Interview series and the weekly Prey update"
Old phpBB2 URL: http://www.bluesbrotherscentral.com/forum/viewtopic.php?t=2374
New vB URL: http://www.bluesbrotherscentral.com/forum/showthread.php?t=2190

Notes

Non existent threads will simply redirect to index.php
This file assumes that your vBulletin was installed to the same URL as your phpBB2 path, eg /forum/ rather than /phpbb/ and /vb/, or /forum/ and /newforum/
This will only work if your 'post' and 'thread' tables have values in the 'importpostid' and 'importthreadid' columns Comments and suggestions welcome

Update
June 20, 2007 - Added changes suggested by 'propeller', now uses 301 redirect for search engines.

bbcentral
02-01-2007, 11:58 AM
*Reserved

FSHD
02-01-2007, 04:02 PM
Thank you so much for this. What a life saver!!!

FSHD
02-01-2007, 04:05 PM
I haven't migrated my board yet to the new vb board. I haven't done the latest phpBB upgrade which came out in December because I knew that I was going to move. I guess that I need to do that in order to use this mod. That's OK...I'm just so happy to have this mod.

I'll upgrade tonight and migrate the boards tomorrow.

Hornstar
02-02-2007, 11:50 AM
What happens if someone wants to post a link to a phpbb forum site, will it change that link as well? or only links which contain your site name in it?

I dont need this, but thought i'd check the above, as that would be important.

Marco van Herwaarden
02-02-2007, 12:23 PM
Are you aware that ImpEx also contain a standard script to do this? (and is supporting more then only phpBB)

bbcentral
02-03-2007, 06:57 AM
If I'd known that it contained a script, then wouldn't I have implemented it on my forum 12 months ago instead of writing my own script? :)

Actually, now I see it.

I REALLY wish this had been more clear at the time when I did the upgrade.

It's been buried away here:
forum/impex/tools/

Anyway from the readme, the url is:
http://www.vbulletin.com/forum/showthread.php?t=178161

I still prefer mine though, I don't want logging or 404 pages or anything like that.

Mine has 1 step, upload the file.

The impex version has many steps:
1) Edit the 404.php file to point to the 404 page, and also include your database user/pass
2) Choose between a 404 and a 301 redirect
3) Create the 404_actions table in your database
4) Setup a .htaccess file to point to 404.php

But it's up to you, you can either upload my file and do nothing else, or you can use the one in impex and spend 5 minutes configuring it, after reading a 163 line readme file.

bbcentral
02-03-2007, 07:05 AM
What happens if someone wants to post a link to a phpbb forum site, will it change that link as well? or only links which contain your site name in it?

I dont need this, but thought i'd check the above, as that would be important.

It took me a few minutes to figure out what you were talking about, but I think you've misunderstood the purpose of this script.

Let's just say you used phpBB2 for a while, maybe a few years. Not everybody would link directly to the forum home page, there might be hundreds of websites directly linking to threads on your forum.
Now, when you switch to vBulletin, anyone who clicks a link to one of those threads from another site will be shown your 404 page, even though the thread still exists. This is because the URL for that thread has now changed.

With my script in place, if someone clicks on a phpBB2 link on another site, and you have since switched to vBulletin, instead of giving a "Page Not Found" error it will silently redirect you to the new vBulletin thread.

Try the 2 demo links in my first post and it should help you understand :)

Soliloquy
02-10-2007, 02:43 AM
This looks like exactly what I need! Except my old phpBB forum was in the /forum directory and the new vBulletin forum is in the root directory. Is there any way to change it?

feldon23
02-27-2007, 08:15 PM
I mentioned this here:
http://www.vbulletin.com/forum/showthread.php?t=163852

bbcentral
03-10-2007, 11:14 PM
This looks like exactly what I need! Except my old phpBB forum was in the /forum directory and the new vBulletin forum is in the root directory. Is there any way to change it?

Try this one:
61703

Upload it into your /forum/ folder, it will include the vB files from the root directory and redirect there, it's customised just for your situation.

nixcraft
04-26-2007, 09:35 AM
Hey, this is an excellent script, i had something like this for my old blog :) you saved my time :D

aam
05-07-2007, 11:00 AM
Does exactly as what it says on the packet. Nice.

Luky
05-07-2007, 12:01 PM
good if you just SEO'ed

Mrdby
05-08-2007, 11:35 AM
i need to see a demo

propeller
05-22-2007, 06:09 AM
This would set 301 redirects for the search engines.

header( "HTTP/1.1 301 Moved Permanently" );
header("Location: ".$redir);
exit();

patch developer
05-23-2007, 04:24 AM
There is something not clear for me , i had a phpBB2 forum which is reside in folder1 and i moved to VBulletin in another folder let us say folder2 , i imported all the data using Impex tool , so i want to confirm this viewtopic.php it should be copied in the old forum folder (folder1) ?

maxicep
05-25-2007, 01:14 PM
do not working on my 3.66.
redirecting to forumhome page

Riccardo83
05-27-2007, 12:54 AM
this is great, what about those who used mod_rewrite on phpBB2 ? SEO Mod

Meaning how do i get this url http://www.alizee-forum.com/topic,14063,.html redirected properly?

Meaning to get it to redirect to http://www.alizee-forum.com/viewtopic.php?t=14063 and ur script will then do redirect to http://www.alizee-forum.com/showthread.php?t=16946

bbcentral
06-20-2007, 08:04 AM
i need to see a demo

There's a working demo in the main post, but I'll repost it here:
Working demo
Thread name "The Apogee Interview series and the weekly Prey update"
Old phpBB2 URL: http://www.bluesbrotherscentral.com/forum/viewtopic.php?t=2374
New vB URL: http://www.bluesbrotherscentral.com/forum/showthread.php?t=2190

This would set 301 redirects for the search engines.

Thanks for that, I can't believe I didn't think of including that when I've used it everywhere else on my site! Added it into the code, released v1.01, and put your name in the credits :)

There is something not clear for me , i had a phpBB2 forum which is reside in folder1 and i moved to VBulletin in another folder let us say folder2 , i imported all the data using Impex tool , so i want to confirm this viewtopic.php it should be copied in the old forum folder (folder1) ?

Your old forum used to be in /folder1/viewtopic.php?t=1234
Your new forum is in /folder2/showthread.php?t=5678
What you're doing is replacing the original viewtopic.php page with my file. Now, you're going to need to modify the viewtopic.php code slightly so it includes the config.php file in folder2.
Line 16 should become:
include_once "../folder2/includes/config.php";
Line 60 should become:
header("Location: /folder2/".$redir);

I think that's all you need to do, but I haven't tested it.

do not working on my 3.66.
redirecting to forumhome page

If it can't get the topic ID or the post ID, then it redirects back to the homepage.
You need to make sure that when you ran Impex it kept all the importpostid and importthreadid values in the vb_thread and vb_post tables. Redirecting to the homepage is the failsafe for threads which have been deleted or invalid links.

this is great, what about those who used mod_rewrite on phpBB2 ? SEO Mod

Meaning how do i get this url http://www.alizee-forum.com/topic,14063,.html redirected properly?

Meaning to get it to redirect to http://www.alizee-forum.com/viewtopic.php?t=14063 and ur script will then do redirect to http://www.alizee-forum.com/showthread.php?t=16946

You're going to have to find a way to do that yourself, I would think you could just copy whatever you were doing for phpBB2. If you used .htaccess, add the same thing to your current .htaccess file.
Just as a guess, maybe:
RewriteRule ^topic,([0-9]*),.html* /viewtopic.php?t=$1
(I genuinely have no idea if that will work, found the snippet on another site)
This should redirect back to /viewtopic.php, which will then check your vBulletin tables for the new Thread or Post ID, and do the redirect as normal.
It's 3 steps instead of 2, but not a huge problem :)

patch developer
06-21-2007, 06:50 AM
Thank you man

it is working fine

Ducks
10-31-2007, 08:56 PM
Big THANKS

momilc
06-12-2012, 11:59 PM
Hello,
I've moved from phpBB3 to Vbulletin 4.2a and it seems your file doesn't work with it. I'll really apreciate if you could make a kind of upgrade of the script :-)

Thx and regards. Mo