Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress + WordPress (mu or not) leads to 404 errors, but p


  • Beau Lebens
    Participant

    @beaulebens

    Background: Installed WPMU (at “/”) and bbPress (at “/forums/”), followed integration instructions (and tweaked to get it all working). I used my WP theme header.php and footer.php as the basis for a bbPress theme, and loaded the full WP engine into bbPress by putting this code in my config.php

    // Load WordPress so we can use the same templates.
    define('WP_BB', 'true');
    require_once dirname(dirname(__FILE__)) . '/wp-blog-header.php';

    Symptoms: Pages load just fine, and all appears successful, but, upon further inspection, all bbPress pages actually return a 404 error in the HTML headers (you can see this using FireBug, or using a HEAD command to the page). NOTE: This will also happen if you create custom pages (not WP “Pages”) that load the WordPress engine – they load fine, but actually throw a 404).

    Explanation: What appears to be happening here, is that the page loads fine, because it is a real page. Internally however, WP doesn’t know about this page (because it’s a bbPress, or custom page), and so it assumes it’s a request for a permalink that it can’t resolve. Thus it throws a 404.

    The internal rewrite system in WP allows you to add new rewrite rules, but appears to only like dealing with “internal” or WP-specific rules. If you add in what it refers to as “non_wp_rules”, then it doesn’t actually apply them (so it still throws a 404).

    The FIX! on the code that I’m running, I have put the following WordPress plugin in place to add rules appropriate for my bbPress installation:

    function mbob_flush_rewrites() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }
    add_action('init', 'mbob_flush_rewrites');

    function mbob_add_rewrites($wp_rewrite) {
    add_rewrite_rule('forums/topic', 'forums/topic.php');
    add_rewrite_rule('forums/forum', 'forums/forum.php');
    add_rewrite_rule('forums', 'forums/index.php');
    $wp_rewrite->rules = array_merge($wp_rewrite->non_wp_rules, $wp_rewrite->rules);
    }
    add_action('generate_rewrite_rules', 'mbob_add_rewrites');

    NOTE: I have removed a lot of my bbPress installation as part of my integration, so I didn’t require any other rules to handle things like profile pages or tags – you probably will need to add them if you use those features.

    Hopefully this will help someone else and prevent you from beating your head against a wall like I almost did :)

    Thanks to sambauers for helping me out with this in #bbpress as well.

    Beau

Viewing 15 replies - 1 through 15 (of 15 total)
  • Beau,

    Which files should you put this code on? I am also installing bbPress on a MU WordPress. I get the same error. I thought maybe it’s because of WP/MU not compatible with bbPress. I have the same install directories (WP/MU on root and bbPress on /forums/). And I am getting the same 404 error on user profile and post.

    Thanks in advance


    Beau Lebens
    Participant

    @beaulebens

    @starnet – The best way is to have it in an auto-load WPMU plugin, which means stick it in a file called “no-404s.php” or something in wp-content/mu-plugins/.


    Vili
    Participant

    @vilimaunula

    Brilliant, absolutely brilliant. I had already got to the stage of banging my head against the wall a few times because of this, but now it’s finally sorted out and my forums don’t throw up those nasty 404s when validating and being indexed by search engines.

    Thanks, beaulebens!

    So close! I have this same issue with my regular installation of WP, and I only realized today (after 3 months) that this is the reason my forums – http://argentinastravel.com/forums/ – are not getting indexed!

    I tried creating a plugin from the code above, but I couldn’t activate it. Can someone please help me with a step by step fix for a regular WP install? Gracias!


    chrishajer
    Participant

    @chrishajer

    What does the content of your plugin look like, and what is the error you are getting when you try to activate it (do you have access to error logs)? Also, what version WordPress are you using( 2.3.3?)

    Thanks for the reply Chris. Yes, I’m using 2.3.3 right now. The content of the plugin code is exactly as above:

    function mbob_flush_rewrites() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }
    add_action('init', 'mbob_flush_rewrites');

    function mbob_add_rewrites($wp_rewrite) {
    add_rewrite_rule('forums/topic', 'forums/topic.php');
    add_rewrite_rule('forums/forum', 'forums/forum.php');
    add_rewrite_rule('forums', 'forums/index.php');
    $wp_rewrite->rules = array_merge($wp_rewrite->non_wp_rules, $wp_rewrite->rules);
    }
    add_action('generate_rewrite_rules', 'mbob_add_rewrites');

    And I’m not getting a specific error really. Simply that when I upload no404s.php with this code to my wp-content/plugins directory, there is no listing in the Plugins tab to even activate it.


    chrishajer
    Participant

    @chrishajer

    No listing in the plugins tab means the plugin is malformed and is seen as just a file in that directory, not a plugin. You are going to need a plugin header, something as simple as this:

    <?php
    /*
    Plugin Name: No 404s
    */
    ?>

    https://codex.wordpress.org/Writing_a_Plugin


    Ryan
    Participant

    @ryannutt

    Works great, although I added a couple of rewrite rules.

    /forum/profile to /forum/profile.php and /forum/tags to /forum/tags.php

    The profile and tags pages were still returning 404 headers.

    Would I be able to use the pretty URLs with this somehow? Or maybe exclude the entire directory of /bbpress/ from wordpress’s URL thing?

    Using WMPU btw

    I faced with the very same problem with two bbpress installations along with a WP. I slightly modified the function is_404() in the /wp-includes/query.php so the function returns true when the requested uri belongs to the forums.

    function is_404 () {

    global $wp_query;

    if (preg_match('/(firstbbpressfoldername|secondbbpressfoldername)/i', $_SERVER))

    {return true;}

    else{

    return $wp_query->is_404;}

    }

    After saving the irritating 404 issue has gone.

    Regards

    Zoli

    This is so annoying guys :(

    What’s the cleanest solution to this, for WP 2.8.6 installed in / and bbPress 1.0.2 installed in /forum/ ?

    Thanks very much, indexing is vital to me.

    Just an update, I read elsewhere that this is deprecated in latest WP versions:

    require_once dirname(dirname(__FILE__)) . '/wp-blog-header.php';

    This should be used instead:

    require_once dirname(dirname(__FILE__)) . '/wp-load.php';


    duvanmonsa
    Participant

    @duvanmonsa

    I had the same error i did this piece of code and the status code will be force to be 200 in my case was when i was showing the user public profile.

    function bbp_fix_users_404_headers() {
      if (bp_displayed_user_id() != 0 && is_404() ) {
        global $wp_query;
        $wp_query->is_404 = false;
        status_header( 200 );
      }
    }
    add_action( 'wp', 'bbp_fix_users_404_headers',0 );

    munkitkat
    Participant

    @munkitkat

    I had already got to the stage of banging my head against the wall a few times because of this, but now it’s finally sorted out and my forums don’t throw up those nasty 404s when validating and being indexed by search engines.


    munkitkat
    Participant

    @munkitkat

    I tried creating a plugin from the code above, but I couldn’t activate it. Can someone please help me with a step by step fix for a regular WP install?

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