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 EditsThis step covers all files that need to be edited. Step 2 covers the template edits.
forumdisplay.php
Find:
[php]foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$navbits["forumdisplay.php?$session[sessionurl]f=$forumID"] = $forumTitle;
}[/php]Replace with:
[php]// ################ 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 ######################[/php]Find:
[php]$thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']);[/php]Below that add:
[php]// ################ MOD_REWRITE HACK ######################
$thread['url'] = strtolower(str_replace(" ", "-", $thread['threadtitle']));
$thread['url'] = ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $thread['url']);
// ################ MOD_REWRITE HACK ######################[/php]
showthread.php
Find:
[php]foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$navbits["forumdisplay.php?$session[sessionurl]f=$forumID"] = $forumTitle;
}[/php]Replace with:
[php]// ################ 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 ######################[/php]
search.php
Find:
[php]$thread = process_thread_array($thread, $lastread["$thread[forumid]"]);[/php]Below that add:
[php]// ################ MOD_REWRITE HACK ######################
$thread['url'] = strtolower(str_replace(" ", "-", $thread['threadtitle']));
$thread['url'] = ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $thread['url']);
// ################ MOD_REWRITE HACK ######################[/php]
includes/functions_forumlist.php
Find:
[php]// do light bulb
$forum['statusicon'] = fetch_forum_lightbulb($forumid, $lastpostinfo, $forum);[/php]Above that add:
[php]// ################ MOD_REWRITE HACK ######################
$forum['url'] = strtolower(str_replace(" ", "-",str_replace("/", "-", $forum['title'])));
// ################ MOD_REWRITE HACK ######################[/php]Find:
[php]$forumperms = $bbuserinfo['forumpermissions']["$forumid"];[/php]Above that add:
[php]// ################ MOD_REWRITE HACK ######################
$forum['url'] = strtolower(str_replace(" ", "-",str_replace("/", "-", $forum['title'])));
// ################ MOD_REWRITE HACK ######################[/php]
includes/functions_online.php
Find:
[php]// ###################### Start showonline #######################[/php]Above that add:
[php]// ###################### MOD_REWRITE HACK #################
function mod_rewrite_title($title)
{
$rewritten = strtolower(str_replace(" ", "-",str_replace("/", "-", $title)));
return ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $rewritten);
}
// ###################### MOD_REWRITE HACK #################[/php]Find all instances of:
[php]$threadtitle[/php]And replace with:
[php]$threadtitle[/php]Find all instances of:
[php]$forumtitle[/php]And replace with:
[php]$forumtitle[/php]Find:
[php]convert_short_varnames($values);
$userinfo['values'] = $values;[/php]Below that add:
[php]// #################### 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 #################[/php]
Step 2 - Template Edits
This step covers all the template edits needed. Step 3 covers the .htaccess file needed.
Within the Forum HomeTemplates group the following templates all require the modification below.
forumhome_forumbit_level1_nopostforumhome_forumbit_level1_postforumhome_forumbit_level2_nopostforumhome_forumbit_level2_postforumhome_subforumbit_nopostforumhome_subforumbit_post
In each of the templates above find:
[php][/php]And replace with:
[php]$forum[title][/php]
In the forumhome_lastpostby template find:
[php]$vbphrase[go_first_unread_in_thread_x]">$lastpostinfo[trimthread][/php]And Replace with:
[php]$vbphrase[go_first_unread_in_thread_x]">$lastpostinfo[trimthread][/php]Find:
[php][/php]And replace with:
[php][/php]Find:[php][/php]And replace with:[php][/php]
In the Threadbit Templates group, the threadbit template requires the following modifications.
Find:
[php][/php]And replace with:
[php][/php]Find:
[php][/php]And replace with:
[php][/php]Find:
[php][/php]And replace with:
[php][/php]Find:
[php][/php]And replace with:
[php][/php]
Step 3 -.htaccess file
Open notepad or your usual text editor and copy and paste the following into a new file.
[php]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][/php]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.
1. In the includes/functions_forumlist.php file where I mention to find
[php]$forumperms = $bbuserinfo['forumpermissions']["$forumid"];[/php] and and above it add
[php]// ################ MOD_REWRITE HACK ######################
$forum['url'] = strtolower(str_replace(" ", "-",str_replace("/", "-", $forum['title'])));
// ################ MOD_REWRITE HACK ######################[/php]There are 3 instances of the line. It's the last instance (around line 530) you place the code above.
2. In the includes/functions_online.php file where I mention replacing all instances of
[php]$threadtitle[/php]with
[php]$threadtitle[/php]and replacing
[php]$forumtitle[/php]with
[php]$forumtitle[/php]If your code has backslashes ( \ ), you need to keep them in the code.
One suggestion: is there any reason why we shouldn't have the mod_rewrite_title() function defined only in includes/functions.php, and call that to rewrite every title in the hack? that way the second element of the function (the [php]ereg_replace("[\/!£$%^&*«»,.;:'#@~{}|=+`¬<>?]+", "", $rewritten);[/php]) could be applied across the board, ensureing that all links across the site will match, making the SEO'ness better (making sure there is only one "page" per page of content).
One suggestion: Maybe putting it all up as a .txt file would prove helpful...or something that doesn't strip the backslashes and "&" bits.
That would be nice as that is what I had seen when I was trying to use some of this, I was having a very hard time when I was doing the searches, untill I noticed that the backslashes were stripped.... so I stopped.
Didn't want to go to far and something go wrong and not knowing where it happened would be a pain to fix.
Hmm...it doesn't seem to work for me...After some editing I got it displaying allright, but the url's lead to error pages... for example http://www.nordinho.com/vbull/f4-the-ultimate-news-forums.html leads to a error page...any idea's how to solve this or where to start?? My testforum is located at www.nordinho.com/vbull
(The last post in thread works fine by the way)
Keith used the wrong rewrite lines...your htaccess file should look like the one below...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?forumid=$1 [L]
hello all... I am thinking of adding vBadvanced CMPS and was wondering if any one is also using it with this Mod_rewrite or have any idea if it will work or not, or any problems that can happen.
If it's not a silly question, how would the the file "external.php" need to be modded, so that RSS feed of the forums would show the HTML threads, rather than the dynamic php URLs?