Skip to:

Rewriting up one level

  • Hey guys,

    I’ve been googling about this for a while now and cant seem to find a solution. If I want to do an SEO rewrite with Rewriterule that causes the file to be written up one level…

    (the equivalent of browser-side linking “../”)

    how would I do that? for example, I have

    Rewriterule ^profile/ etc etc

    What do I do..




    No idea really.. any thoughts on this would be great. I basically want it to go up one level and ignore my forums directory..

    so instead of /forums/profile/ its /profile/

Viewing 7 replies - 1 through 7 (of 7 total)

  • Sam Bauers


    Even if you got the Rewrite rules written correctly, the page wold not load due to the checks carried out that check the URL in the function repermalink().

    I already edited the template-functions.php to

    $r = bb_get_option(‘uri’) . “../user/” . $user->$column . ( 1 < $page ? “/page/$page” : ” );

    } else {

    $r = bb_get_option(‘uri’) . “profile.php?id=$user->ID” . ( 1 < $page ? “&page=$page” : ” );


    I can access it from /user/username/ one level up (ie.root)

    So accessing the link isnt a problem. I just need it to be rewritten

    can I get a reply on this please

    Sam Bauers


    Add this to your sites root directory .htaccess file.

    This assumes that your bbPress install is in a subdirectory of your sites root called “forums”.

    These rules need to be added before any WordPress rules.

    The rewrite will work, but bb_repermalink() will change the URL so that it appears as it normally would.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^users/([^/]+)/page/([0-9]+)/?$ /forums/profile.php?id=$1&page=$2 [L,QSA]
    RewriteRule ^users/([^/]+)/([^/]+)/?$ /forums/profile.php?id=$1&tab=$2 [L,QSA]
    RewriteRule ^users/([^/]+)/([^/]+)/page/([0-9]+)/?$ /forums/profile.php?id=$1&tab=$2&page=$3 [L,QSA]
    RewriteRule ^users/([^/]+)/?$ /forums/profile.php?id=$1 [L,QSA]

    Awesome! I learnt something new ([^/]+) .. very cool.

    Ok the rewrite worked.

    Now just to figure out this repermalink…

    Any ideas guys? I’ll go look around myself in the meantime ^_^

    Sam Bauers


    My advice is don’t try to change bb_repermalink().

    Just to qualify myself, I rewrote bb_repermalink() a while back to implement slug-based permalinks. It’s a tricky beast, and the most complex part is the profile-page case.

    But if you must, then you should start by turning debugging on $bb->debug = 1 in config.php should do it. Then when you hit your link you should get some readable debug info at the top of your page.

    The critical part of stopping the redirect is on line 1708 of bb-includes/functions.php, you have to make that condition happy to stop the redirect to it’s preferred permalink location. That may involve simply modifying the get_user_profile_link() and also the get_profile_tab_link() functions, but I’m not 100% sure about that.


    As you suggested, I was able to modify get_user_profile_link() function in template-functions.php to prevent the redirection. Mod_rewrite will now rewrite to the profile page properly, without redirecting it.

    But now, it shows I’m no longer logged in when I’m on a rewritten page, even though I am. When I try to log in. It just reloads the page.

    Here’s the mod in_user_profile_link():

    function get_user_profile_link( $id = 0, $page = 1 ) {
    $user = bb_get_user( bb_get_user_id( $id ) );
    $rewrite = bb_get_option( 'mod_rewrite' );
    if ( $rewrite ) {
    if ( $rewrite === 'slugs' ) {
    $column = 'user_nicename';
    } else {
    $column = 'ID';
    $r = bb_get_option('uri') . "profile/" . $user->$column . ( 1 < $page ? "/page/$page" : '' );
    } else {
    $r = bb_get_option('uri') . "profile/" . $user->$column . ( 1 < $page ? "/page/$page" : '' );

    $r = str_replace('forums/profile/' . $user->$column , "profile/" . $user->$column, $r);
    return apply_filters( 'get_user_profile_link', $r, $user->ID );


    My goal is create a short URL such as

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar