Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.6 > vBulletin 3.6 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
404 / 301 after import redirect on import ids Details »»
404 / 301 after import redirect on import ids
Version: 1.00, by Jerry Jerry is offline
Developer Last Online: Oct 2010 Show Printable Version Email this Page

Category: Miscellaneous Hacks - Version: 3.6.9 Rating:
Released: 04-22-2008 Last Update: Never Installs: 52
Re-useable Code  
No support by the author.

After importing from a source board there will be internal and external links that point to the old URLS.

During the import the origional import id's are kept (for one import) so a redirect can be calculated to find the new user/forum/thread/post, by looking up the old import{$type}id.

ImpEx currently alters the table to add the import id, though a planned future version will have this separated so multi-import sites can be managed,

The original discussion thread on vBulletin.com :

http://www.vbulletin.com/forum/showthread.php?t=178161

It is advised that $do_404 = false; is set so the 301 is sent with the new URL to update search engines.

The script needs setting up and customising to each site as the domains and URLs can be different.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #32  
Old 09-08-2008, 10:47 PM
trigatch4 trigatch4 is offline
 
Join Date: Feb 2007
Posts: 90
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Indeed, I copied/pasted wrong but fixed above. Threads look like this:
http://mysite.com/index.php/topic,775.0.html

I have pretty much no programming experience so while appreciate your valiant effort, it doesn't look like I'll get very far although I'm going to give it a try.
Reply With Quote
  #33  
Old 09-12-2008, 02:46 AM
trigatch4 trigatch4 is offline
 
Join Date: Feb 2007
Posts: 90
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A friend took a look and here is what they came up with. I'm hoping someone can go over it and see if it is okay as I can't really "test" the 301 redirect until I'm live with the new site. Greatly appreciate your help

This sets the variables we use below to determine if we need to parse the old urls.
Code:
case 'smf'        
        $old_forum_script    = "index.php?board=";                    //http://mysite.com/index.php?board=5.0
        $old_thread_script   = "index.php/topic,";                    //http://mysite.com/index.php/topic,775.0.html
        $old_post_script     = ".msg";                                //http://mysite.com/index.php/topic,603.msg6020.html#new
        $old_user_script     = "index.php?action=profile,u=";         //http://mysite.com/index.php?action=profile;u=41
        break;
This is the actual parser.

Forum Link - Tell it to grab the querystring value for 'board'
Code:
            // It's a forum link
            if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}{$old_forum_script}") === 0)
            {
                $action = 'forum';
                $old_id = intval($_GET['board']);
                $sql = "SELECT forumid FROM {$tableprefix}forum WHERE importforumid={$old_id}";
            }

Thread Link - Tell it to grab the int value for thread id
Code:
// It's a thread link
            if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}{$old_thread_script}") === 0)
            {
                $action = 'thread';
                // Cuts 775 out of this : /index.php/topic,775.0.html
                $old_id = intval(substr(substr($_SERVER['REQUEST_URI'], 17), 0,  strpos(substr($_SERVER['REQUEST_URI'], 17), '.')));
                $sql = "SELECT threadid FROM {$tableprefix}thread WHERE importthreadid={$old_id}";
            }
Post Link - Tell it to grab the int value for post
Code:
 // It's a post link
            if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}{$old_post_script}") === 0)
            {
                
                $action = 'post';
                // Cuts 6020 out of this /index.php/topic,603.msg6020.html#new
                $old_id = (substr(substr($_SERVER['REQUEST_URI'], intval(strpos(substr($_SERVER['REQUEST_URI'], 0), '.msg')) + 4), 0,  strpos(substr($_SERVER['REQUEST_URI'], intval(strpos(substr($_SERVER['REQUEST_URI'], 0), '.msg')) + 4), '.')));

                $sql = "SELECT postid FROM {$tableprefix}post WHERE importpostid={$old_id}";

            }

User Link - Tell it to grab the int value for users profile
Code:
// It's a user link
            if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}{$old_user_script}") === 0)
            {
                $action = 'user';
                // Cuts 41 out of this : index.php?action=profile;u=41
                $old_id = intval(substr($_SERVER['REQUEST_URI'], 28, 4));
                $sql = "SELECT userid FROM {$tableprefix}user WHERE importuserid={$old_id}";
            }
Reply With Quote
  #34  
Old 09-12-2008, 11:59 PM
tommythejoat's Avatar
tommythejoat tommythejoat is offline
 
Join Date: Apr 2008
Location: Boston
Posts: 155
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I looked over the code and it looks fine to me. There is one nuance that is not really important. When you are using intval to parse a number from a string, you don't need to snip off the number, you just need to start at the right place and intval will stop converting when it finds a non-numeric character.

While we are discussing this, I decided I needed to move the importid's into their own table and built this table:
Code:
CREATE TABLE `importedid` (
`idtype` VARCHAR( 25 ) NOT NULL,
`oldid` INT UNSIGNED NOT NULL,
`newid` INT UNSIGNED NOT NULL,
PRIMARY KEY (`idtype`, `oldid`)
) TYPE = MYISAM;
I then populated the table from the importids of each of the imported tables assigning the values post, thread, forum, attachment and user to the idtype field. Here is an example of one of the queries I used to do this.
Code:
INSERT INTO `importedid` (`idtype`, `oldid`, `newid`)
SELECT "attach", `importattachmentid`, `attachmentid`
FROM `attachment` WHERE `importattachmentid`>0
The sql that I am trying to use to query this table is:

PHP Code:
        if (strpos($_SERVER['REQUEST_URI'], "/{$old_folder}{$old_thread_script}") === 0)
        {
            
$action 'thread';
            
$old_id intval(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], ';gtid=')+6)); //to the end of the string
            
if (strpos($_SERVER['REQUEST_URI'], ';pagenumber='))
            {
                
$page intval(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], ';pagenumber=')+12));
            }
            
$sql "SELECT newid FROM {$tableprefix}importedid WHERE oldid={$old_id} AND idtype = {$action}"
When I copy this up and enter a url for the old board in my browser, it fails to find the new id. The result is the code 10 id not found no matter what I enter. I am guessing there is something wrong with the $sql, but I cannot figure out what it might be. I would appreciate any advice. I can't see why this doesn't work and maybe I am just too close to it. The board is live now and I don't want to take it down to play with this.

The older version that takes the id's out of the various importid's in the tables works just fine. I put it back each time I try to fix the above with a new idea and the new idea does not work.
Reply With Quote
  #35  
Old 09-14-2008, 04:56 PM
trigatch4 trigatch4 is offline
 
Join Date: Feb 2007
Posts: 90
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need the SQL database for this to work? Do I just point it to my existing SQL database that hosts the VB or do I need to make a new line and/or database separately?

I thought that the 404.php would dynamically parse the old URL and forward to a new URL based on the parsing self contained in the 404.php document. Am I wrong?
Reply With Quote
  #36  
Old 09-14-2008, 05:28 PM
tommythejoat's Avatar
tommythejoat tommythejoat is offline
 
Join Date: Apr 2008
Location: Boston
Posts: 155
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by trigatch4 View Post
You need the SQL database for this to work? Do I just point it to my existing SQL database that hosts the VB or do I need to make a new line and/or database separately?

I thought that the 404.php would dynamically parse the old URL and forward to a new URL based on the parsing self contained in the 404.php document. Am I wrong?
The parser fetches the old id for whatever object it references. The object has a new id that it is using in the new vB. ImpEx puts the old id in the object tables with the new id and the program looks them up to do the translation.

If you use the basic approach, you cannot clean up your database and remove the importid's from it. This is generally not a big deal unless you are doing multiple imports.

I just wanted to clean it up by moving the importid's into a separate table.

I also added some other external reference url's that had shown up in the log table. I decided that those url's for attachments, printthread requests, etc. should also be translated appropriately.

I also made the url for items that are not found be a thread on my message board talking about the trap facility.
Reply With Quote
  #37  
Old 09-14-2008, 08:09 PM
trigatch4 trigatch4 is offline
 
Join Date: Feb 2007
Posts: 90
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

UPDATE: everything seems to work properly except ONE HUGE THING:

nothing after /index.php/ triggers a 404 but rather loads the forum index at whatever URL is input. All of SMF's urls come after /index.php which makes this a huge disaster.

I'm not sure why this is happening. Error reporting doesn't help because the 404 is never triggered to begin with. Anyone?
Reply With Quote
  #38  
Old 10-10-2008, 08:14 PM
jca2112's Avatar
jca2112 jca2112 is offline
 
Join Date: Sep 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm also having a similar problem. The 404.php simply redirects to the front page of the forums/index.php regardless of the link. The script doesn't seem to be seeing the URI request.

I assume it is because of the old IPB url versus the new VB url I'm using. I'm trying to forward to my current test environment. (IP and urls changed to protect the innocent.)

Old IPB link:
http://mysite.com/forums/index.php?showtopic=2400

should translate/forward to

New VB link:
http://192.168.2.1/~mysite/forums/sh...ad.php?t=47000

I assume the script is having trouble using an IP + ~home directory style link? Is that the issue? Turning on debug shows no results, so it's obviously not seeing the urls.

Any ideas? Appreciate any help/info.
Reply With Quote
  #39  
Old 10-16-2008, 08:01 PM
jca2112's Avatar
jca2112 jca2112 is offline
 
Join Date: Sep 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm. It looks like vBulletin isn't passing on a 404 error because the old url is pointing to "index.php?showtopic=", and vBulletin will automagically display "index.php" regardless of the "?showtopic=". Is there any way to stop vBulletin from doing this so it will properly call the 404.php file?
Reply With Quote
  #40  
Old 10-16-2008, 09:48 PM
tommythejoat's Avatar
tommythejoat tommythejoat is offline
 
Join Date: Apr 2008
Location: Boston
Posts: 155
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It sounds like you are not pointing to a missing file.

It is critical that the old url resolve to a different location than the new message board. In the absence of that you will not get a 404 "missing file" error.

If the old message board is also vBulletin and you put the new one in the same location, you cannot get a 404 message and therefore cannot trap it.
Reply With Quote
  #41  
Old 10-16-2008, 10:24 PM
jca2112's Avatar
jca2112 jca2112 is offline
 
Join Date: Sep 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm guessing it has to do with this IPB (Invision Power Board) issue with the 404 redirection script.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06016 seconds
  • Memory Usage 2,332KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete