MyBB Community Forums

Full Version: mod rewrite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, just downloaded mybb and looking to make the URLS more seo friendly using apaches mod rewrite. I can't find a hack for this anywhere so have been writing my own but can't seem to get the forum page numbers working.

I want to point the page numbers to forum1-1.htm, forum1-2.htm to /forumdisplay.php?fid=1&sortby=lastpost&order=desc&page=1 and /forumdisplay.php?fid=1&sortby=lastpost&order=desc&page=2 using the code below in apaches httpd.conf

RewriteRule ^/forum([0-9]+)\-([0-9]+)\.htm$ /forumdisplay.php?fid=$1&sortby=lastpost&order=desc&page=$2

But can't figure out what code needs to go in Multipage Pagination Templates or if i need to make any changes to the actual php. I've got the thread pagination working just fine but forum pagination seems to be implimented differently. Can anyone let me know what to do or point me in the direction of a hack for mybb to do this

Cheers

Tom

I did this a while back, and I'm afraid it does need quite a lot of fiddling with in the templates, pretty much every reference to showforum.php etc.

Here's the code I used if you want to have a look:

RewriteRule t(.*)-p(.*)\.html$ /showthread.php?tid=$1&page=$2
RewriteRule t(.*)-(lastpost|nextnewest|nextoldest)\.html$ /showthread.php?tid=$1&action=$2
RewriteRule t(.*)\.html$ /showthread.php?tid=$1
RewriteRule f([0-9]+)\.html$ /forumdisplay.php?fid=$1 [L]

That does the following:
  • Converts showthread.php?tid=1234 to t1234.html
  • Converts showthread.php?tid=1234&page=2 to t1234-p2.html
  • Converts showthread.php?tid=1234&goto=lastpost/nextnewest/nextoldest to t1234-lastpost/nextnewest/nextoldest.html
  • Converts forumdisplay.php?fid=123 to f123.html

Once i got into the swing of it, it didn't take me long to change everything - but it does get a bit monotonous Wink

James Smile
Here's a list of all the places that refer to '$url' (the thing that needs to be changed i think)
You probably won't need to alter some of these, and some don't have relevance, but this is what i found anyway:

-bash-2.05b$ grep -R '$url =' *
admin/index.php:                $url = $dstore[2];
admin/mscadmin.php:             $url = $dstore[2];
admin/downloads.php:            $url = addslashes($url);
admin/downloads.php:            $url = addslashes($url);
arcade/functions/functions.php:         $url = str_replace( "&", "&", $url );
arcade/functions/parser.php:            $url = trim($url);
arcade/functions/parser.php:            $url = str_replace( " ", "%20", $url );
downloads.php:          $url = addslashes($url);
editpost.php:           $url = "polls.php?action=newpoll&tid=$tid&polloptions=$numpolloptions";
editpost.php:           $url = "showthread.php?tid=$tid&pid=$pid#pid$pid";
global.php:  $url = str_replace(" ", "%20", $url);
inc/functions.php:      $url = $REQUEST_URI;
links.php:      $url = addslashes($url);
member.php:     //if(strpos($url, "member.php?action=register") !== false || $url = "member.php")
member.php:     //      $url = "";
misc.php:               $url = $settings['bburl']."/rss.php";
moderation.php:                 $url = "forumdisplay.php?fid=$fid";
moderation.php:                 $url = "showthread.php?tid=$tid";
moderation.php:                 $url = "forumdisplay.php?fid=$fid";
moderation.php:                 $url = "showthread.php?tid=$tid";
newreply.php:           $url = "showthread.php?tid=$tid";
newreply.php:           $url = "showthread.php?tid=$tid&pid=$pid#pid$pid";
newthread.php:          $url = "polls.php?action=newpoll&tid=$tid&polloptions=$numpolloptions";
newthread.php:          $url = "forumdisplay.php?fid=$fid";
newthread.php:          $url = "showthread.php?tid=$tid";
stats/inc/functions.php:        $url = $REQUEST_URI;
usercp2.php:            $url = $HTTP_REFERER;
usercp2.php:            $url = "showthread.php?tid=$tid";
usercp2.php:            $url = $HTTP_REFERER;
usercp2.php:            $url = "usercp.php?action=favorites";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "index.php";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "showthread.php?tid=$tid";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "usercp.php?action=forumsubscriptions";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "usercp.php?action=subscriptions";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "usercp.php?action=forumsubscriptions";
usercp2.php:                    $url = $HTTP_REFERER;
usercp2.php:                    $url = "usercp.php?action=subscriptions";
usercp2.php:            $url = $HTTP_REFERER;
usercp2.php:            $url = "usercp.php?action=favorites";

Hope it helps Smile
Cheers james that looks like exactly what I need - It seems like a lot of work though Sad ah well...
no probs Smile
It should be worth it though, it makes a site a lot more Google-friendly Smile
I think I've found an easier way to do it for just the page numbers

in forumdisplay.php change

$multipage = multipage($threadcount, $perpage, $page, "viewforum.php?fid=$fid?&sortby=$sortby&order=$order&datecut=$datecut");

to

$multipage = multipage($threadcount, $perpage, $page, "forum$fid-");

And in templates change everything in Multipage Pagination Templates by removing the page= and putting .htm on the end.