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 thread is resolved. Here is a description of the problem and solution.

Problem:
In certain cases, the .htacess may get overwritten with the language folder. However, this issue is not caused by WPML. The problem actually comes from certain third-party plugins calling flush_rewrite_rules(true) function too many times. Clients who may experience this problem should consider if they have recently installed a plugin that may affect rewrite rules or .htaccess file in any way.

Solution:
The proper fix is for the third-party plugin to flush the rewrite rules only once.
As a temporary workaround you can add the following lines to the functions.php of your theme:

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/errata/htaccess-is-rewritten-with-language-folder/

This topic contains 24 replies, has 3 voices.

Last updated by Andrew Ambrosius 4 months, 2 weeks ago.

Assigned support staff: Oscar Miras.

Author Posts
May 20, 2019 at 10:18 am #3845963

Andrew Ambrosius

Good Afternoon,

Website: hidden link
Bug: hidden link

If you see the vide there is a bug - that when we change the language and then hit refresh button an error 500 comes up.

I spoke to my hosting provider they said there is nothing wrong with the server. I have also contacted Thrive Themes for the same.

Please can you look into the same and see if there is any issue with the plugin or if there are any specific settings that you require us to do.

Regards,

May 20, 2019 at 11:27 am #3846355

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi there,

It would be good if you can provide me with the WordPress debug.log (not WPML debug information).

To enable it, open your wp-config.php file and look for define(‘WP_DEBUG’, false);. Change it to:

define('WP_DEBUG', true);
define( 'WP_DEBUG_LOG', true );

In this case, the errors will be saved to a debug.log log file inside the /wp-content/ directory.

If you can paste your debug.log to pastebin.com and provide me that link it would be great! (This is the cleanest way because sometimes the logs are long and create a complete mess in the discussion).

Additionally, also provide us with the server error log usually located in your site document root.

Please let me know the details.

Kind regards
Raja

May 21, 2019 at 7:40 am #3852737

Andrew Ambrosius

The website is broken, can you please investigate. Not a good look for customers. Please see attached screenshot

May 21, 2019 at 8:16 am #3852997

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

I have enabled the debug log, the site is very slow responding now. I am working on this.

May 21, 2019 at 8:24 am #3853159

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

HI there,

This seems like a cache issue. I am able to access the site when I disabled the cache. Try clearing the site cache (from super cache plugin) and resave the permalinks. I hope this solves your issue.

Kind regards
Raja

May 22, 2019 at 10:26 am #3864275

Andrew Ambrosius

The cache has been disbaled. CloudFlare Caching is now enabled. Permalink has been refreshed.

I am still getting the same error. Please can you check.

May 22, 2019 at 11:09 am #3864633

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

HI,

You can try disabling Cloudflare cache as well, I am unable to get server error logs, could you please check with your hosting provider and enable all error reporting for your site. As of now, it seems to log only the notices which is of not much use. Unless we have access to the error logs it's not easy for us to arrive at a solution.

Kind regards
Raja

May 22, 2019 at 12:48 pm #3865651

Andrew Ambrosius

Good Afternoon,

I have disabled CloudFlare and wp supercache. Please can you check now.

Regards,

May 22, 2019 at 12:55 pm #3865749

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks for the update,

Can you please ask your hosting to enable the server error logs to log All errors. Without that, we have no clue about the error. If the settings are already enabled please request them for the server error log.

Kind regards
Raja

May 22, 2019 at 5:25 pm #3868407

Andrew Ambrosius

Hello

This is the message from our hosting provider

---
As we can see, logging enabled. But there were no errors logged from 27.01 for castellsimmerscom.com

---

May 23, 2019 at 6:59 am #3871751

Andrew Ambrosius

Hi team,

I really need to get this issue fixed, it is having a negative impact on my business and stopping me from running an online marketing campaign that should have gone live last week.

Regards,

Andrew

May 23, 2019 at 7:22 am #3872003

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hey Andrew,

I would request to clone your site to our private server for a detailed debugging. Details about migration will be sent in my next private reply.

Kind regards
Raja

May 23, 2019 at 2:22 pm #3876661

Andrew Ambrosius

Thank you.

Once I will start I will let you know and update you.

Regards,

May 23, 2019 at 5:35 pm #3878409

Andrew Ambrosius

Good Evening,

Migration completed successfully

Source :hidden link

Destination :hidden link

Please let me know if you need any further updates.

Regards,

May 24, 2019 at 5:18 am #3881197

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hey Andrew,

Thank you for reporting, I have tested this on the clone site the issue seems to be related to disabled rewrite in server level or inaccessible or corrupt .htaccess file.

The issue is fixed in the clone site after fixing the .htaccess file
hidden link

However, the same does not work in your setup. Please confirm whether you see any errors WPML > language > language URL format under languages per directory option?

I tried to validate the languages directory option using hidden link which returned me a 500 error. which means the URL redirect is not enabled in the server, Please check with your hosting provider whether URL redirect is enabled in your server and also make sure you have proper file permisisons

Please refer https://wpml.org/documentation/getting-started-guide/language-setup/cannot-activate-language-directories/#what-does-being-able-to-rewrite-urls-mean

Please let me know if you need further assistance.

Kind regards
Raja