I figured it was time that a revised edition of this tutorial be written up. So, I asked Dani if it was ok and well..... here it is :D
This revised edition includes how to make your forumhome, forumdisplay, showthread and who's online sections all show search engine friendly urls as well as in the navbar. It includes the id & name in the url of forums and threads.
Please take care when performing each step, making sure you perform the correct action - adding code ABOVE or BELOW other lines or REPLACING code.
Step 1 - File Edits
This step covers all files that need to be edited. Step 2 covers the template edits.
forumdisplay.php
Find:
foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$navbits["forumdisplay.php?$session[sessionurl]f=$forumID"] = $forumTitle;
}
Replace with:
// ################ MOD_REWRITE HACK ######################
foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$forumURL = strtolower(str_replace(" ", "-",str_replace("/", "-", $forumTitle)));
$navbits["f$forumID-$forumURL.html"] = $forumTitle;
}
// ################ MOD_REWRITE HACK ######################
Find:
$thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']);
Below that add:
// ################ MOD_REWRITE HACK ######################
$thread['url'] = strtolower(str_replace(" ", "-", $thread['threadtitle']));
$thread['url'] = ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $thread['url']);
// ################ MOD_REWRITE HACK ######################
showthread.php
Find:
foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$navbits["forumdisplay.php?$session[sessionurl]f=$forumID"] = $forumTitle;
}
Replace with:
// ################ MOD_REWRITE HACK ######################
foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$forumURL = strtolower(str_replace(" ", "-",str_replace("/", "-", $forumTitle)));
$navbits["f$forumID-$forumURL.html"] = $forumTitle;
}
// ################ MOD_REWRITE HACK ######################
search.php
Find:
$thread = process_thread_array($thread, $lastread["$thread[forumid]"]);
Below that add:
// ################ MOD_REWRITE HACK ######################
$thread['url'] = strtolower(str_replace(" ", "-", $thread['threadtitle']));
$thread['url'] = ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $thread['url']);
// ################ MOD_REWRITE HACK ######################
includes/functions_forumlist.php
Find:
// do light bulb
$forum['statusicon'] = fetch_forum_lightbulb($forumid, $lastpostinfo, $forum);
Above that add:
// ################ MOD_REWRITE HACK ######################
$forum['url'] = strtolower(str_replace(" ", "-",str_replace("/", "-", $forum['title'])));
// ################ MOD_REWRITE HACK ######################
Find:
$forumperms = $bbuserinfo['forumpermissions']["$forumid"];
Above that add:
// ################ MOD_REWRITE HACK ######################
$forum['url'] = strtolower(str_replace(" ", "-",str_replace("/", "-", $forum['title'])));
// ################ MOD_REWRITE HACK ######################
includes/functions_online.php
Find:
// ###################### Start showonline #######################
Above that add:
// ###################### MOD_REWRITE HACK #################
function mod_rewrite_title($title)
{
$rewritten = strtolower(str_replace(" ", "-",str_replace("/", "-", $title)));
return ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $rewritten);
}
// ###################### MOD_REWRITE HACK #################
Find all instances of:
<a href=\"showthread.php?$session[sessionurl]t=$threadid\" title=\"$threadpreview\">$threadtitle</a>
And replace with:
<a href=\"t$threadid-" .mod_rewrite_title($threadtitle). ".html\" title=\"$threadpreview\">$threadtitle</a>
Find all instances of:
<a href=\"forumdisplay.php?$session[sessionurl]f=$forumid\">$forumtitle</a>
And replace with:
<a href=\"f$forumid-" .mod_rewrite_title($forumtitle). ".html\">$forumtitle</a>
Find:
convert_short_varnames($values);
$userinfo['values'] = $values;
Below that add:
// #################### MOD_REWRITE HACK #################
if (eregi("t([0-9]+)-(.*).html$", $filename, $tmatch)) {
$filename = 'showthread.php';
$values['threadid'] = $tmatch[1];
}
if (eregi("f([0-9]+)-(.*).html$", $filename, $fmatch)) {
$filename = 'forumdisplay.php';
$values['forumid'] = $fmatch[1];
}
// #################### MOD_REWRITE HACK #################
Step 2 - Template Edits
This step covers all the template edits needed. Step 3 covers the .htaccess file needed.
Within the Forum Home Templates group the following templates all require the modification below.
forumhome_forumbit_level1_nopost
forumhome_forumbit_level1_post
forumhome_forumbit_level2_nopost
forumhome_forumbit_level2_post
forumhome_subforumbit_nopost
forumhome_subforumbit_post
In each of the templates above find:
<a href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]">
And replace with:
<a href="f$forum[forumid]-$forum[url].html">$forum[title]</a>
In the forumhome_lastpostby template find:
<a href="showthread.php?$session[sessionurl]goto=newpost&t=$lastpostinfo[lastthreadid]" title="<phrase 1="$lastpostinfo[lastthread]">$vbphrase[go_first_unread_in_thread_x]</phrase>"><strong>$lastpostinfo[trimthread]</strong></a>
And Replace with:
<a href="newpostinthread$lastpostinfo[lastthreadid].html" title="<phrase 1="$lastpostinfo[lastthread]">$vbphrase[go_first_unread_in_thread_x]</phrase>"><strong>$lastpostinfo[trimthread]</strong></a>
Find:
<a href="showthread.php?$session[sessionurl]goto=lastpost&t=$lastpostinfo[lastthreadid]"><img class="inlineimg" src="$stylevar[imgdir_button]/lastpost.gif" alt="$vbphrase[go_to_last_post]" border="0" /></a>
And replace with:
<a href="lastpostinthread$lastpostinfo[lastthreadid].html"><img class="inlineimg" src="$stylevar[imgdir_button]/lastpost.gif" alt="$vbphrase[go_to_last_post]" border="0" /></a>
Find:
<a href="showthread.php?$session[sessionurl]goto=lastpost&t=$lastpostinfo[lastthreadid]"><img class="inlineimg" src="$stylevar[imgdir_button]/lastpost.gif" alt="$vbphrase[go_to_last_post]" border="0" /></a>
And replace with:
<a href="lastpostinthread$lastpostinfo[lastthreadid].html"><img class="inlineimg" src="$stylevar[imgdir_button]/lastpost.gif" alt="$vbphrase[go_to_last_post]" border="0" /></a>
In the Threadbit Templates group, the threadbit template requires the following modifications.
Find:
<a href="showthread.php?$session[sessionurl]goto=lastpost&t=$thread[threadid]">
And replace with:
<a href="lastpostinthread$thread[threadid].html">
Find:
<a href="showthread.php?$session[sessionurl]goto=newpost&t=$thread[threadid]">
And replace with:
<a href="newpostinthread$thread[threadid].html">
Find:
<a href="showthread.php?$session[sessionurl]t=$thread[threadid]$thread[highlight]">
And replace with:
<a href="t$thread[threadid]-$thread[url].html">
Find:
<a href="showthread.php?$session[sessionurl]goto=lastpost&t=$thread[threadid]">
And replace with:
<a href="lastpostinthread[threadid].html">
Step 3 -.htaccess file
Open notepad or your usual text editor and copy and paste the following into a new file.
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^t([0-9]+).html$ showthread.php?t=$1 [L]
RewriteRule ^lastpostinthread([0-9]+).html$ showthread.php?goto=lastpost&t=$1 [L]
RewriteRule ^newpostinthread([0-9]+).html$ showthread.php?goto=newpost&t=$1 [L]
RewriteRule ^f([0-9]+).html$ forumdisplay.php?f=$1 [L]
Save this file as .htaccess and upload it to your forum's root directory.
And that's it!
Now just sit back and wait for the search engines to spider your new urls :o
If I missed any steps (god forbid) or there's an error in any of the steps, please let me know and I'll update it.