Permalinks Slugs Modification – removing forum
-
I want to install bbPress permalinks slugs on http://www.example.com/forum. The forum will be hosted in http://www.exmaple.com/forum/
I am trying to remove the “forum” from the forum’s url because the normal output its ugly.
So from:
http://www.example.com/forum/forum/forum-name
to get
http://www.example.com/forum/forum-name
I’ve edited in /bb-includes/template-functions.php the $link from
$link = bb_get_option( ‘uri’ ) . “forum/” . $forum->$column . ( 1 < $page ? “/page/$page” : ” );
to
$link = bb_get_option( ‘uri’ ) . $forum->$column . ( 1 < $page ? “/page/$page” : ” );
but I do not manage to make the new link to work for .httaccess. Is there a way to do it?
Thanx.
-
Without core hacks or writing your own plugin that hooks into the get_forum_link function and the bb_repermalink function it’s not possible. Your .htaccess file may be correct, but the links generated on the forum won’t work without changing the what those functions expect. I suggest you change the name of the subdirectory you are placing your forums in – that would be the path of least resistance..
Thanx for the response.
I tried to follow how the links are made in functions.php. In bb_repermalink() the case ‘forum-page’ needs to be “hacked”
$forum_id = bb_get_id_from_slug(‘forum’, $permalink);
Is the ‘forum’ the “forum” I want to remove?
Thanx.
> Is the ‘forum’ the “forum” I want to remove?
No. It’s a little more complicated than that. In fact, that part you say needs to be hacked, needs to be left completely alone. Really, you are asking for a world of pain by attempting this. It took me hours to write and test the slugs support. Seriously, just rename your forum directory – it’s not worth the hours you will spend.
There has got to be a fairly easy way to remove the “forums/” slug from the URL… anyone know how yet?
Hey, I’m trying to figure this out also. Anyone figured out a way to remove the first “forum” in http://www.example.com/forum/forum/forum-name. So that the URL is shorter? I tried doing it with mod_rewrite, but having some issues with bbPress automatically redirecting.
I did something similar, but it required a core hack. I renamed the second “forum” to “board”. It required two steps:
1. With version 0.8.3, I modified line 363 of /bb-includes/template-functions.php to this:
$link = bb_get_option( 'uri' ) . "board/" . $forum->$column . ( 1 < $page ? "/page/$page" : '' );2. I created an htaccess file by copying the text from /bb-admin/rewrite-rules.php, with two extra lines:
RewriteRule ^board/(.+)/page/([0-9]+)$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^board/(.+)/?$ /forum.php?id=$1 [L,QSA]Hey bobby, just curious. Why did you have to change the second “forum” to “board”? Is there anyway to just leave it as “forum”?
I wanted the forum-specific URLs to look like this:
* http://boards.weddingbee.com/board/beehive
If you make the right edits to that core file and an htaccess file, I think the URL can be anything you want…
Hi bobby, I tried out your hack in bbPress 0.9, and it doesn’t seem to work. Here’s what I did:
I have my bbPress directory installed in a directory called “forums” in the root web directory. So the URL to access the forums’ home page is:
http://www.example.com/forumsand accessing a forum titled “test forum” is at this URL:
http://www.example.com/forums/forum/test-foruma topic titled “test topic” is at this URL:
http://www.example.com/forums/topic/test-forumI implemented your hack, and changed “forum” to “board” in the template-functions.php. I copied the rewrite rules from rewrite-rules.php and placed them into .htaccess file in the root web directory. I also added the two lines of code you suggested in that file:
RewriteRule ^board/(.+)/page/([0-9]+)$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^board/(.+)/?$ /forum.php?id=$1 [L,QSA]I also tried adding this to the rewrite-rules.php:
RewriteRule ^board/([^/]+)/page/([0-9]+)/?$ <?php bb_option( 'path' ); ?>topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^board/([^/]+)/?$ <?php bb_option( 'path' ); ?>topic.php?id=$1 [L,QSA]When I go to this URL:
http://www.example.com/board/test-forumI get a 404 error.
However, when I go to this url:
http://www.example.com/forums/forum/test-forum/It redirects and changes the URL in the address bar in the browser window changes:
http://www.example.com/forums/board/test-forum/That also brings up a 404 page.
Also, when I go this URL:
http://www.example.com/topic/test-topicThe URL works, but it redirects and changes the URL in the address bar in the browser window changes to:
http://www.example.com/forums/topic/test-forumI am a little perplexed as to what is going on.
Can you post a link to your site?
Hey bobby, here it is here:
You said: “I also tried adding this to the rewrite-rules.php”. That’s unnecessary. You just need to add those lines to your htaccess file, which should contain the contents of the page located at http://www.lifeclever.com/forums/bb-admin/rewrite-rules.php. Did you add those lines to your htaccess file?
Hi Bobby, yes I added those lines to the .htaccess file as well. It didn’t seem to fix the problem. So I tried adding it to rewrite-rules.php also.
Just found an earlier thread which hits on a similar problem with shortening the bbPress URL:
In the thread’s example. In shows you how to shorten a url like:
http://www.example.com/bbpress/forum/pets-discussions/topic/my-sweet-dogto:
http://www.example.com/bbpress/pets-discussions/my-sweet-dogNow, if it could also be shortened to:
http://www.example.com/pets-discussions/my-sweet-dogThat would be even better.
It could work like that I think if there were no website (like WordPress) in the www root. Otherwise, how does the server know it’s a bbPress page vs. a WordPress page?
If you are running a forum only on a domain, then it would be silly to have it in any sort of directory at all. Otherwise, if you have a website in the root, you have to put bbPress into some sort of directory to prevent confusion.
Chris, you have a point. However the URL structure of forums and topics always begin with “forum” or “topic”. As in:
http://www.example.com/bbpress/forum/pets-discussions/http://www.example.com/bbpress/topic/my-sweet-dogSo it would seem that it should be possible to remove the “bbpress” from the URL without interfering with a WordPress installation.
Having said that, I think the solution proposed in the thread I referred to in my last post (https://bbpress.org/forums/topic/nicer-slug-url-rewrite-plugin-done) is a much more elegant solution for shortening the bbPress URLs.
- The topic ‘Permalinks Slugs Modification – removing forum’ is closed to new replies.