PDA

View Full Version : Fix a redirect URL


Immortal
01-03-2006, 09:00 PM
Hello everyone,

I've used preg_match_all to replace all of my URLs to be more SEO friendly. However, I tried to use preg_match_all (global_complete hook) for redirects such as showthread.php?p=id#postid and search.php?searchid=id however it does not want to cooperate since they are "redirects" and not URLs...I've tried using the following code.


$found = preg_match_all('#showthread\.php\?p=([0-9]+)\#post([0-9]+)#i', $output, $matches);

if($found)
{
// Build an array of ID's
$ids = array();

for($i = 0; $i < $found; $i++)
{
if(is_numeric($matches[1][$i]))
$ids[] = $matches[1][$i];
}
$ids = implode(',', $ids);

// Go through each
$res = $vbulletin->db->query_read("SELECT threadid, postid FROM " . TABLE_PREFIX . "post WHERE postid IN($ids)");

while($t = $vbulletin->db->fetch_array($res))
{

$tid = $t['threadid'];
$pid = $t['postid'];
$threadinfo = $vbulletin->db->query_first("SELECT title, forumid FROM thread WHERE threadid='$tid'");
$title = urlize($threadinfo['title']);
$fid = $threadinfo['forumid'];
$f = fetch_foruminfo($fid);
$fname = urlize($f['title']);



$output = str_replace("showthread.php?p=$pid#post$pid", "$fname/p-$title-$pid.html#$pid", $output);
}


}


But preg_match_all found nothing. Is there a special way I have to do this or in a different hook then global_complete? I really don't want to modify any files if I can stay away from that. Any help would be greatly appreciated :)

Immortal
01-07-2006, 12:21 AM
Just giving this a kind bump up (sorry!). I've also tried to replace the code in case newpost in showthread.php but it's still redirecting. It honestly doesn't matter how it can be done as long as its correct at this point :nervous:

Immortal
01-10-2006, 07:58 PM
Okay, I thought I had it, but apprently not. I stuck this code in global_start:

if(THIS_SCRIPT == 'showthread') {
if(!isset($_GET['is_vrewrite'])){

//Let's see if we're doing a thread, or a post.
$threadid = $_GET['t'];

if(!empty($threadid)) {
$thread = $vbulletin->db->query_first("SELECT title, forumid FROM " . TABLE_PREFIX . "thread WHERE threadid='$threadid'");

$title = $thread['title'];
$fid = $thread['forumid'];
$f = $vbulletin->forumcache[$fid];
$fid = $f['forumid'];
$ftitle = $f['title'];
exec_header_redirect("$ftitle/$title-$threadid.html");

}

else
{ die('we are on a post'); }

}
}

But its redirecting as the forums over and over, but how can that be if its not in a while? :S

yayvb
01-30-2006, 11:56 PM
Surprising that no one has any ideas, maybe it's just an impossibility. ;)