{"id":15327970,"date":"2024-02-21T13:01:27","date_gmt":"2024-02-21T13:01:27","guid":{"rendered":"https:\/\/wpml.org\/?post_type=faq&#038;p=15327970"},"modified":"2024-02-21T13:01:33","modified_gmt":"2024-02-21T13:01:33","slug":"why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website","status":"publish","type":"faq","link":"https:\/\/wpml.org\/ar\/faq\/why-is-htaccess-getting-overwritten-with-the-language-folder-on-my-wpml-website\/","title":{"rendered":"Why is .htaccess getting overwritten with the language folder on my WPML website?"},"content":{"rendered":"\n<p class=\"lead\">Sometimes, third-party plugins call the <strong>flush_rewrite_rules(true)<\/strong> function too often. This leads to changes in the rewrite rules in your <strong>.htaccess <\/strong>file, which can cause issues on your WordPress site.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the flush_rewrite_rules(true) function and what happens when plugins call it too often?<\/h2>\n\n\n\n<p>The <strong>flush_rewrite_rules(true)<\/strong> function in WordPress is used to regenerate rewrite rules, which are rules that tell your website how to handle URLs. It&#8217;s a critical function but when used too often, it can cause WordPress to overwrite the<strong> .htaccess<\/strong> file.&nbsp;<\/p>\n\n\n\n<p>This becomes problematic when it occurs during every page request or while you browse your site in another language. When this happens, WPML goes ahead and adds the language folder to<strong> home_url <\/strong>as usual. However, this results in an incorrect <strong>RewriteBase<\/strong> in <strong>.htaccess<\/strong>, causing your website&#8217;s front-end to break.&nbsp;<\/p>\n\n\n\n<p>In this case, WPML is acting correctly and the problem is entirely in the plugin calling this function too often.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How can I identify the plugin causing this and fix the issue?<\/h2>\n\n\n\n<p>Identifying the specific plugin causing this issue can be challenging. It involves testing in a minimal environment and deactivating plugins one by one. After finding the responsible plugin, you would need to contact the author and request that they add a fix that limits the rewrite rule flushing to happen only once.&nbsp;<\/p>\n\n\n\n<p>As a quick workaround, you can instruct WPML not to add the language folder. To do this, add the following code to your theme&#8217;s <strong>functions.php<\/strong> file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_filter(&#039;mod_rewrite_rules&#039;, &#039;fix_rewritebase&#039;);\nfunction fix_rewritebase($rules){\n    $home_root = parse_url(home_url());\n    if ( isset( $home_root&#x5B;&#039;path&#039;] ) ) {\n        $home_root = trailingslashit($home_root&#x5B;&#039;path&#039;]);\n    } else {\n        $home_root = &#039;\/&#039;;\n    }\n \n    $wpml_root = parse_url(get_option(&#039;home&#039;));\n    if ( isset( $wpml_root&#x5B;&#039;path&#039;] ) ) {\n        $wpml_root = trailingslashit($wpml_root&#x5B;&#039;path&#039;]);\n    } else {\n        $wpml_root = &#039;\/&#039;;\n    }\n \n    $rules = str_replace(&quot;RewriteBase $home_root&quot;, &quot;RewriteBase $wpml_root&quot;, $rules);\n    $rules = str_replace(&quot;RewriteRule . $home_root&quot;, &quot;RewriteRule . $wpml_root&quot;, $rules);\n \n    return $rules;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">What should I do if I need more help?<\/h2>\n\n\n\n<p>If you continue to face problems or need specific assistance, please <a href=\"https:\/\/wpml.org\/forums\/forum\/english-support\/\">contact our support team<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, third-party plugins call the flush_rewrite_rules(true) function too often. This leads to changes in the rewrite rules in your .htaccess file, which can cause issues on your WordPress site. What is the flush_rewrite_rules(true) function and what happens when plugins call it too often? The flush_rewrite_rules(true) function in WordPress is used to regenerate rewrite rules, which [&hellip;]<\/p>\n","protected":false},"author":538393,"featured_media":0,"menu_order":11,"template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"ep_exclude_from_search":false,"footnotes":""},"faq-category":[26133],"class_list":["post-15327970","faq","type-faq","status-publish","hentry","faq-category-troubleshooting"],"_links":{"self":[{"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/faq\/15327970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/users\/538393"}],"version-history":[{"count":8,"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/faq\/15327970\/revisions"}],"predecessor-version":[{"id":15328057,"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/faq\/15327970\/revisions\/15328057"}],"wp:attachment":[{"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/media?parent=15327970"}],"wp:term":[{"taxonomy":"faq-category","embeddable":true,"href":"https:\/\/wpml.org\/ar\/wp-json\/wp\/v2\/faq-category?post=15327970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}