Home›Supporto›Assistenza in italiano›[Chiuso] flush_rewrite_rules(true) corrupts .htaccess RewriteBase when using directory language mode
[Chiuso] flush_rewrite_rules(true) corrupts .htaccess RewriteBase when using directory language mode
Questo è il forum di assistenza tecnica di WPML, il plug-in multilingue di WordPress.
La sua lettura è permessa a tutti, ma la pubblicazione è riservata esclusivamente ai clienti di WPML. Il team di WPML risponde sul forum 6 giorni su 7, 22 ore su 24.
Sun
Mon
Tue
Wed
Thu
Fri
Sat
-
8:00 – 12:00
8:00 – 12:00
8:00 – 12:00
8:00 – 12:00
8:00 – 12:00
-
-
13:00 – 17:00
13:00 – 17:00
13:00 – 17:00
13:00 – 17:00
13:00 – 17:00
-
Fuso orario del supporto: Asia/Ho_Chi_Minh (GMT+07:00)
We are experiencing a critical bug with WPML when using directory-based language URLs (language_negotiation_type=1).
ENVIRONMENT:
- WordPress 6.8.5, PHP 8.2, LiteSpeed
- WPML 4.9.2, WPML String Translation 3.5.1
- The Events Calendar 6.15.18 + Events Calendar Pro 7.7.14
- Languages: English (default) + German (/de/)
- Slug translation: enabled
BUG 1 - .htaccess corruption:
When flush_rewrite_rules(true) is called (hard flush), WPML writes incorrect values in the WordPress .htaccess block:
RewriteBase /de/
RewriteRule . /de/index.php [L]
instead of:
RewriteBase /
RewriteRule . /index.php [L]
This causes ALL pages (both EN and DE) to return 404 at the web server level (before PHP is even reached). The issue happens regardless of context: WP-CLI, wp-admin Permalink Settings page, or programmatic calls.
We had to add a filter on 'mod_rewrite_rules' to fix the RewriteBase after WPML corrupts it.
BUG 2 - Incomplete rewrite rules in non-web contexts:
When flush_rewrite_rules() is called during WP-CLI execution, cron, or the upgrader_process_complete hook, the rewrite rules are saved to the database without WPML's translated slug variants. This causes intermittent 404 errors on translated pages until a flush happens in a proper web request context where WPML is fully initialized.
EXPECTED BEHAVIOR:
1. flush_rewrite_rules(true) should always write RewriteBase / regardless of the current language context
2. flush_rewrite_rules() in any context (CLI, cron, upgrader) should produce complete rewrite rules including all language variants
WORKAROUND:
We created a custom plugin that:
- Hooks into 'mod_rewrite_rules' to fix the RewriteBase
- Defers flush to the next normal web request (not upgrader/cron)
- Uses only soft flush (false) to avoid .htaccess corruption
This is a production site with paying customers, so the intermittent 404s are causing real business impact. We would appreciate if the WPML team could investigate and fix these issues.
Thank you for the reply, but I have to be honest: I'm quite disappointed with how this ticket was handled.
The FAQ article you linked suggests a `mod_rewrite_rules` filter to fix the RewriteBase. As clearly stated in our original report, we already have that workaround in place - it's part of the custom plugin we built specifically to work around this WPML bug. The ticket was closed as "resolved" without anyone actually reading what we wrote.
A few points I'd like to raise:
1. **We reported two distinct bugs, not one.** The second issue (incomplete rewrite rules when flush happens in CLI, cron, or upgrader contexts) was completely ignored. This is the one causing intermittent 404s on translated pages.
2. **The FAQ article frames this as a third-party plugin problem.** We respectfully disagree. When `flush_rewrite_rules(true)` is called, WPML should never inject a language subdirectory into the global `RewriteBase`. That breaks the entire site, not just translated pages. The `.htaccess` WordPress block must always have `RewriteBase /` regardless of the current language context. This is a bug in WPML, not in the caller.
3. **We are paying customers running a production site.** We spent significant time diagnosing the root cause, building a workaround, and writing a detailed bug report. We expected the technical team to at least acknowledge the issues, not to close the ticket with a generic FAQ link.
We would appreciate it if this ticket could be reopened and assigned to a developer who can evaluate the two bugs we described. We are happy to provide additional debugging information, access to a staging environment, or any other detail that may help.
Lingue: Inglese (English )Vietnamita (Vietnamese )
Fuso orario: Asia/Ho_Chi_Minh (GMT+07:00)
Hi Francesco,
I'm Long from the WPML Development team, I'm happy to help you with this issue.
I understand the situation that you are experiencing. There were some similar issues in the past with loading content in the frontend when using the language URL format "Different languages in directories". And the workaround in the FAQ that our supporter shared fixed the issue.
Let me know if the workaround (similar to the code in your custom plugin) doesn't fix the case when the function flush_rewrite_rules is called by using CLI, cron ...
In the meantime, I'm going to discuss this issue with our team to propose a long-term solution instead of using a custom code like that.
Thanks for your understanding and patience.
L'argomento '[Chiuso] flush_rewrite_rules(true) corrupts .htaccess RewriteBase when using directory language mode' è chiuso a nuove risposte.