最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wordpress - WPML: After switching from ?lang=en to en, redirects are not working correctly - Stack Overflow

programmeradmin4浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论