Problem
I changed the WPML language URL format in WordPress from ?lang=en to /en/. However, after the change, the pages are not redirecting correctly.
Example:
- Before: /?lang=en
- Expected Redirect: /
- Actual Redirect: /?lang=en
To enforce the redirection, I added the following .htaccess rules:
RewriteEngine On
RewriteBase /
# Extract language parameter and redirect correctly
RewriteCond %{QUERY_STRING} lang=([a-zA-Z-]+)
RewriteRule ^(.*)$ /%1/$1? [R=301,L]
# Remove language parameter from the URL
RewriteCond %{QUERY_STRING} lang=([a-zA-Z-]+)
RewriteRule ^ /%1%{REQUEST_URI}? [R=301,L]
# Standard WordPress rules
RewriteRule ^index\.php$ - [L]
# Redirect to the WordPress parser
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Question
Why is WPML still redirecting to /de/, even though the .htaccess rules should enforce the correct redirection? Are there any WPML-specific settings or workarounds to fix this issue?
What I Have Tried
- Checked the WPML language URL format: It is set to "Directories for each language".
- Disabled automatic browser language redirection: WPML should not redirect based on the browser language.
- Resaved Permalinks in WordPress: To ensure the new structure is applied.
- Cleared all caches: Browser cache, WP cache, and server-side caches.
- Tested different .htaccess rules, but the issue persists.
Expected Behavior
Any URL with ?lang=en should be redirected to /en/.
Other URLs should remain unaffected.
Actual Behavior
WPML still redirects to the default language /de/.
The language setting does not seem to be applied correctly.