You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress(WPML)多语言站点.htaccess规则:URL特定字符串忽略配置

Got it, let's sort out this .htaccess rule for your WPML-powered bilingual WordPress site. The goal here is to internally rewrite requests to /en/xyz to serve the content from /xyz while keeping the original URL intact—here's how to make it work:

Step 1: Add the Custom Rewrite Rule

Insert this code before the default WordPress .htaccess block (the one wrapped in # BEGIN WordPress and # END WordPress). This ensures our rule runs first before WordPress takes over all request handling:

# BEGIN XYZ Page Language Exception
<IfModule mod_rewrite.c>
RewriteEngine On
# Internally rewrite /en/xyz (and /en/xyz/) to /xyz, preserving any extra path segments
RewriteRule ^en/xyz(/.*)?$ /xyz$1 [L,NC,PT]
</IfModule>
# END XYZ Page Language Exception

Let's Break Down the Rule

  • ^en/xyz(/.*)?$: This pattern matches URLs starting with en/xyz, including optional trailing slashes or extra path segments (like /en/xyz/subpage if you ever need it).
  • /xyz$1: This is the target path—we're pointing the request to the main German version of the page, with $1 capturing and preserving any extra parts of the URL after xyz.
  • [L,NC,PT]:
    • L: Marks this as the last rule to process if the match is found, preventing further unnecessary rewrites.
    • NC: Makes the match case-insensitive (useful if someone types /EN/XYZ by mistake).
    • PT: Passes the rewritten path to the next phase of processing, so WordPress can correctly recognize and serve the /xyz page content without breaking things.

Important Notes

  • Clear Cache: After updating .htaccess, clear your browser cache or test in incognito mode to avoid cached redirects messing with your changes.
  • WPML Compatibility: Since WPML handles language routing via its own rules, placing our custom rule before WordPress's default block ensures it takes priority without conflicting with WPML's core logic.
  • Query Strings: Any query parameters (like /en/xyz?foo=bar) will automatically be preserved and passed to the /xyz page—no extra configuration needed for that.

内容的提问来源于stack exchange,提问作者Akshat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:19:59