Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ad-inserter domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cookie-law-info domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/blog.webeats.it/httpdocs/wp-includes/functions.php on line 6114
WordPress - WPML fix error 500 con il RewriteBase - Blog WebEats

WPML fix error 500  – Breve guida su come fixare l’errore 500 dato da WPML in alcune situazioni

Interfacciandomi con il multilingua di WordPress mi è capitato più volte di dover usare plugin come WPML (al momento è il miglior plugin per avere il multilingua su WordPress).

Su alcuni siti però mi è capitato che il frontend andasse in errore 500. Questa cosa è dovuta da alcuni plugin che richiedono il flush delle rewrite rules – flush_rewrite_rules(true) – e quindi la riscrittura del file htaccess.

Per risolvere questo problema ho trovato un link sul sito ufficiale di WPML che spiega come risolvere il fastidioso problema del RewriteBase

https://wpml.org/errata/htaccess-is-rewritten-with-language-folder

Però in situazioni in cui ci sono plugin esterni di cache o di hiding, come ad esempio Hide My WP può succedere che quelle regole non bastano, perciò dovremo aggiungere al nostro file function.php del tema o al nostro plugin personalizzato questo piccolo filtro

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);
    $rules = str_replace($home_root."wp-includes/", "/wp-includes/", $rules);
	$rules = str_replace($home_root."wp-content/", "/wp-content/", $rules);
	$rules = str_replace($home_root."wp-admin/", "/wp-admin/", $rules);
	$rules = str_replace($home_root."nothing_404_404", "/nothing_404_404", $rules);
	$rules = str_replace($home_root."/index.php?", "/index.php?", $rules);
	
	
    return $rules;
}