Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
A bug triggered by specific plugins, producing a 500 error intermittently.
Solution:
We have found out that it is an internal server error triggered by the fact that the .htaccess is altered and /en/ is the rewrite base:

<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /en/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /en/index.php [L]
</ifmodule>

This occurs primarily on a specific page and happens on every heartbeat. This happens when third-party plugins call the flush_rewrite_rules(true) function too often. This can change the rewrite rules in your .htaccess file and cause issues on your WordPress site. The full explanation can be found here:
https://wpml.org/faq/why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website/.

We suggest implementing the workaround on your staging site by adding the following function to the theme's functions.php file.

add_filter('mod_rewrite_rules', 'fix_rewritebase');
function fix_rewritebase($rules){
    $home_root = parse_url(home_url());
    if ( isset( $home_root['path'] ) ) {
        $home_root = trailingslashit($home_root['path']);
    } else {
        $home_root = '/';
    }
   
    $wpml_root = parse_url(get_option('home'));
    if ( isset( $wpml_root['path'] ) ) {
        $wpml_root = trailingslashit($wpml_root['path']);
    } else {
        $wpml_root = '/';
    }
   
    $rules = str_replace("RewriteBase $home_root", "RewriteBase $wpml_root", $rules);
    $rules = str_replace("RewriteRule . $home_root", "RewriteRule . $wpml_root", $rules);
   
    return $rules;
}

Relevant Documentation:
https://wpml.org/faq/why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website/

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 14 replies, has 0 voices.

Last updated by sarahD-3 2 months, 2 weeks ago.

Assisted by: Itamar.

Author Posts
January 29, 2026 at 10:18 pm #17775302

sarahD-3

Thanks for all your help. That solution seems to be working.