How to remove forum and topic keyword from bbpress url

By Ashish Mohta

I had been trying lot of forum softwares ( around 5 till now ) from last Friday and was testing BBPRESS yesterday. The new version9.x has lot of improvement over its 8.x version but one thing I found common in both of them

  • “Forum” keyword was appended when you accesss any forum e.g http://sitename.com/<forum-directory>/forum/<forum slug>
  • “topic” keyword was also appended for every post made e.g http://sitename.com<forum-directory>/topic/<actualy topic slug>

Now I understand why both the keywords are reqired but again from SEO point it has no meaning unless somebody runs a forum on “forums” topic. The next thing I did was look around for a hack and luckily at this post there was a solution , but not actual plugin was supported. I copied the code given there and tested around and was successful.

Before I start, I have just tested around with the code given by the memebers over there. So test it before you use it. And moreover I am not supporting it as I did not make it and cant do it either.

I made a plugin from the code given and took re-write code for .htaccess files. Here is how they look

PLUGIN:( Taken from the forum link )

<?php
/*
Plugin Name: Remove Topic Forum
Plugin URI: http://bbpress.org/
Description: Allows to remove forum and topic word in url
Author: Ashish Mohta
Version: 1.0
Author URI: http://www.technospot.net/blogs/
*/

function my_get_forum_link_filter( $link , $forum_id = 0 ) {
//retrieve the forum object
$forum = get_forum( get_forum_id( $forum_id ));

//check for rewrite
$rewrite = bb_get_option( ‘mod_rewrite’ );
if ( $rewrite ) {
//what kind of rewrite there is? slug use “forum_slug” column, else the column is “forum_id”
$column = ($rewrite === ’slugs’)?(’forum_slug’):(’forum_id’);

// change /forum/pets-discussions in /pets-discussions
// this work only if the rewrite module is modded!
// and this work only if the slugged name will NEVER
// be a reserved word like “rss” or “bb-images”
// and this is achieved by a filter on bb_slug_sanitize
$link = str_replace(’forum/’ . $forum->$column , $forum->$column, $link);
}
return $link.”/”; // Very important line! // Added extra slash :Ashish
}

add_filter( ‘get_forum_link’, ‘my_get_forum_link_filter’ );

function my_get_topic_link_filter( $link, $topic_id = 0) {
//retrieve the topic object
$topic = get_topic( get_topic_id( $topic_id ));

//retrieve the forum object that is the topic container
$forum = get_forum( get_forum_id( $topic->forum_id ));

//check for rewrite
$rewrite = bb_get_option( ‘mod_rewrite’ );
if ( $rewrite ) {
//what kind of rewrite there is? slug use “forum_slug” column, else the column is “forum_id”
$column = ($rewrite === ’slugs’)?(’forum_slug’):(’forum_id’);

//create the “forum/pets-discussions” chunk to show the hierarchical relation forum->topic
$forum_nice_uri = “forum/” . $forum->$column . “/”;

//attach the hierarchical chunk to the link
$link = str_replace(bb_get_option(’uri’), bb_get_option(’uri’) . $forum_nice_uri, $link);

// change /forum/pets-discussions/topic/my-sweet-dog in /pets-discussions/my-sweet-dog
// this work only if the rewrite module is modded!
// and this work only if the slugged name will NEVER
// be a reserved word like “rss” or “bb-images”
// and this is achieved by a filter on bb_slug_sanitize
$link = str_replace(’forum/’ . $forum->$column , $forum->$column, $link);
$link = str_replace(’topic/’ . $topic->$column , $topic->$column, $link);
}

return $link.”/” ; // Very important line! // Added Extra Slash :Ashish
}

add_filter( ‘get_topic_link’, ‘my_get_topic_link_filter’ );

function my_bb_slug_sanitize_filter( $text_slug, $text_original = ”, $length = 0 ) {
// add “r-” by regex when the string begins with “bb-” or “my-” or is a reserved word
return preg_replace(’/^(my-.*|bb-.*|rss|tags|view|profiles)$/’, ‘r-$1′, $text_slug);
}

add_filter( ‘bb_slug_sanitize’, ‘my_bb_slug_sanitize_filter’ );

?>

.htcaccess file:

( Taken from one same forum link and modified a little. You will need to remove the MULTIVIEW from your existing .htaccess file )

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forums

Options +FollowSymlinks

RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ profile.php?id=$1 [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ rss.php [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ rss.php?profile=$1 [L,QSA]

RewriteRule ^([^.]+)/([^.]+)/page/([0-9]+)/?$ topic.php?id=$2&page=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^.]+)/?$ topic.php?id=$2 [L,QSA]

RewriteRule ^([^/.]+)/page/([0-9]+)/?$ forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ forum.php?id=$1 [L,QSA]
</IfModule>

Place the plugin file in my-plugin directory and .htaccess file in bbpress root directory. Active the plugin. and it should work fine.

The Problem I find with this.

  • The Link to BBpress admin board link does not work from main site. It redirects to home page. You will need to manually type the link to go inside.
  • In case you type something which does not exists as http://sitename.com/<bbpress-directory>/sdaksda it returns http://sitename.com/<bbpress-directory>// . An extra slash.

Except these 2 there is no problem I see so far but Its not easy to predict as I dont have lot of posts or users. So if you want to try it out download the files here . You can give your feedback here if you can improve it. And If somebody wants they can support the plugin and enhance it. You can see demo of this on the forum I tested on but You wont be able to register and anyways it just a test forum


Vote This Post DownVote This Post Up (+5 rating, 1 votes)
Loading ... Loading ...
Comment or Discuss

About The Author of this article:
Ashish is one of the co-author of this blog and writes on various interesting softwares, PC tips and more. You can read more of his articles here.

Enjoyed this article? Download our Toolbar ( for Free ) and read us more quickly or Free Subscribe to the Full RSS Feed or Get Post like this in your Inbox Click to get via Email ( You will have to confirm by checking you Inbox)


  • Tags: , ,
  • Read More Stories from Workshop

  • No Comments Yet

    You can be the first to comment!

    Leave a comment Share your thoughts with the world

    Scroll Down and Check footer for more details



    • Recent Comments:

      • michael: how do you do this on vista? i saw a commnet referring to this but i couldnt find where you wrote the answer
      • Jahad: hi is there a way of removing this as i installed it but a certain game wouldn’t run without directx...
      • AaronTigno: i got the (The application for project ‘C:\Program Files\Microsoft DirectX SDK (April...
      • pitas: very good
      • kimmy: U can also try this web site:http://www.freesmsfrompctomobile.co m
      • Fernando: I started using this over the weekend with my son’s laptop. Unfortunately the problem I found with...
      • Garth: I’ve seen a better solution that does this and much more. Check out http://roohit.com It is so versatile...
      • VLadimir: fefewf
      • Ricardo Ferreira: I would rather kill myself than buy windows, good lord, lock me up already, viva le Pirate Bay!
      • Busnut: Great buzz about Drop Box. Please send me an invite.

    Technology Blogs - Blog Top Sites