Skip to:

BP .htaccess rule causes server CPU spikes

  • Eric Kuznacic


    I had an issue with a client site that the BP team may want to look into, in the event that it is affecting more sites than just mine.

    The issue: Running the latest version of BuddyPress (10.2), I had a client site and server that were seeing spikes to 100% CPU and high RAM usage — but only when a logged-in user opened the WordPress media library (/wp-admin/upload.php).

    My hosting support first told me it was a plugin error, then I was told it was a theme error. But we were unable to find any evidence of this. I cloned the live site, deactivated all plugins and switched to a default WP theme, and the issue still occurred.

    There were no related items in the Apache or Nginx error logs, but the PHP access log fills with lines like this, seemingly for every media file:

    (server IP) – [15/Apr/2022:15:57:37 +0000] “GET /index.php?bp-attachment=13109/NorthCrawford-300×225.jpg” 301 0 – 798 14702 0.648 8388608 9.27% 3.09% “/?bp-attachment=13109/NorthCrawford-300×225.jpg”

    The solution: This is what I received from my hosting support:

    The issue is BuddyPress created htaccess that redirects all wp-content/uploads/bp-attachments/ to ?bp_attachments= URL. The redirects spawn heaps of apache and php-fpm which also cause the issue . They created this sample htaccess found on the directory below

    /public_html/wp-content/uploads/bp-attachments# cat .htaccess

    RewriteEngine On
    RewriteBase /
    RewriteRule (.+) ?bp-attachment=$1 [R=302,NC]

    The htaccess has been renamed so, when you load medias, it should no longer reach 100%

    The solution was to take the .htaccess file out of the equation by renaming it, which is only a temporary fix. I presume this file would be overwritten upon the next BP update?

    If that’s the case, how would I keep this from happening, aside from renaming the offending .htaccess file each time there is a BP update?

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