Skip Navigation

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

Problem:
If you're using the MasterStudy LMS plugin recommended by WPML and notice that your website becomes inaccessible due to htaccess modifications, this might be relevant to you. The issue arises when third-party plugins frequently call the

flush_rewrite_rules(true)

function, leading to unwanted changes in the htaccess file.
Solution:
We recommend following these steps to address the issue:
1. Ensure you back up your site for safety.
2. Insert the following code into the functions.php file 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;
}

3. Re-save your permalinks from the Settings >> Permalinks page by pressing the Save Changes button.
4. Clear all types of caches including site/server, plugin, CDN, and browser caches.
For more details, visit https://wpml.org/faq/why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website/

If this solution does not resolve your issue or seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket at https://wpml.org/forums/forum/english-support/.

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 3 replies, has 2 voices.

Last updated by Noman 1 year ago.

Assisted by: Noman.

Author Posts
June 21, 2024 at 5:53 pm #15777699

adilB-5

Background of the issue:
Hello,
I am using the plugin MasterStudy LMS that WPML is recommending and supporting as per here:
https://wpml.org/plugin/masterstudy-lms-learning-management-system/
https://wpml.org/plugin-functionality/lms/
When I use this plugin it modifies the htaccess and my website becomes inaccessible.
Here is what is modified:

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

is replaced by :

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]

Also in this page WPML says this is a known issue and is corrected in recent WPML update , but it's not the case as problem is still happening :

https://wpml.org/forums/topic/htaccess-rewrite-2/

Symptoms:

Questions:

June 23, 2024 at 7:56 am #15792613

Noman
WPML Supporter since 06/2016

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting WPML Support. Sorry for any confusion, this issue arises due to some third party plugins when they call flush_rewrite_rules(true) function too often and it can only be fixed directly by the plugin author.

As a quick workaround, could you please follow the below steps and see if this resolves the issue:

1. Please take a backup of your site first for safety reasons.

2. Please add the below code in the functions.php file 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;
}

3. Please re-save the permalinks from the Settings >> Permalinks page by pressing the Save Changes button.

4. Please delete all sorts of caches on your site/server cache if any / plugin cache / CDN cache, clear the browser cache, and then see if it resolves the issue afterward.

Here you can see more details about it:
https://wpml.org/faq/why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website/

Please let me know the results,
Thank you for your cooperation

June 30, 2024 at 3:03 pm #15862647

adilB-5

Hello,

In one of the tickets WPML said that this issue has been resolved in wpml recent update ? is it confirmed , otherwise is it planned to solve in next versions.
I think this is a serious issue that need to be adressed in future fixes

July 1, 2024 at 4:35 pm #15869888

Noman
WPML Supporter since 06/2016

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

When we spot a compatibility conflict, we need to replicate this issue at fresh WP site in order to escalate it to our 2nd tier support. To replicate this issue at fresh WP site, Could you please follow the below steps:

1. Please login to the fresh WP site by clicking on the auto login URL:
hidden link

2. Please install the MasterStudy LMS plugin.

3. Configure WPML and MasterStudy LMS plugins as you did on your site.

4. If the issue is reproducible then please let me know steps which you followed to reproduce this issue.

Please note that we only need above mentioned plugin functionality, you don't need to set up an entire website or clone your existing site. You can see more details here: https://wpml.org/faq/how-to-reproduce-issues-and-share-them-with-wpml-support/

Thank you for your cooperation