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

技术求助:使用.htaccess实现https://example.com/dev/kampaaniad/?lang=ru到https://example.com/dev/ru/kampaaniad/的重定向

Redirect Specific Query String URL to Clean Path in .htaccess

Hey there, here's the working .htaccess setup to redirect https://example.com/dev/kampaaniad/?lang=ru to https://example.com/dev/ru/kampaaniad/, and it plays nicely with your existing WordPress rewrite rules:

<IfModule mod_rewrite.c>
RewriteEngine On
# Custom redirect rule - place BEFORE WordPress rules!
RewriteCond %{QUERY_STRING} ^lang=ru$
RewriteRule ^dev/kampaaniad/$ /dev/ru/kampaaniad/ [QSD,R=302,L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /dev/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dev/index.php [L]
</IfModule>
# END WordPress

Quick breakdown of the custom rule:

  • RewriteCond %{QUERY_STRING} ^lang=ru$: Ensures we only target requests where the query string is exactly lang=ru (no extra parameters attached)
  • RewriteRule ^dev/kampaaniad/$ /dev/ru/kampaaniad/: Maps the old path to the new clean path
  • Flags explained:
    • QSD: Drops the original query string so ?lang=ru doesn't appear in the redirected URL
    • R=302: Uses a temporary redirect (change to R=301 once you've confirmed it works and want a permanent redirect for SEO)
    • L: Stops processing any further rewrite rules once this one executes

Important note: Make sure the custom redirect rule is placed before the WordPress block. WordPress's rewrite rules will catch all unmatched requests if they come first, so putting your rule above ensures it runs first.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 15:12:40