weird Internal Server Error – no error log produced

I’ve found this question which describes the same issue i’m facing. The accepted solution didn’t work for me, but after a bit more research I’ve found this solution from WPML.

I’ve noticed that after calling the endpoint the .htaccess was getting rewritten, this part:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^en/wp-login.php /wp-login.php [QSA,L]
RewriteRule ^fr/wp-login.php /wp-login.php [QSA,L]
RewriteRule ^de/wp-login.php /wp-login.php [QSA,L]
RewriteRule ^it/wp-login.php /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Options -Indexes

gets rewritten as:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /it/
RewriteRule ^index\.php$ - [L]
RewriteRule ^en/wp-login.php /it/wp-login.php [QSA,L]
RewriteRule ^fr/wp-login.php /it/wp-login.php [QSA,L]
RewriteRule ^de/wp-login.php /it/wp-login.php [QSA,L]
RewriteRule ^it/wp-login.php /it/wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /it/index.php [L]
</IfModule>
Options -Indexes

After applying the suggested solution from WPML:

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="https://wordpress.stackexchange.com/";
    }
 
    $wpml_root = parse_url(get_option('home'));
    if ( isset( $wpml_root['path'] ) ) {
        $wpml_root = trailingslashit($wpml_root['path']);
    } else {
        $wpml_root="https://wordpress.stackexchange.com/";
    }
 
    $rules = str_replace("RewriteBase $home_root", "RewriteBase $wpml_root", $rules);
    $rules = str_replace("RewriteRule . $home_root", "RewriteRule . $wpml_root", $rules);
 
    return $rules;
}

I can see that the values for RewriteBase / and RewriteRule . /index.php [L] don’t get updated anymore and the Internal Server Error disappears.

In my case I guess the issue was caused by developing the website in a language and then changing it and transferring the website. I’ll contact WPML to let them know about the issue, also I still don’t get what’s causing the rewrite of the .htaccess after calling the endpoint.