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

关于带ID的301重定向(htaccess)至新域名的技术问询

Fixing 301 Redirect for key.php with Query Parameters in .htaccess

Hey Matthias, let's get that redirect issue sorted out! The rule you're currently using targets the root URL (^$) with a query string starting with id=00, which is why it doesn't work for your key.php links—we need to adjust it to specifically match that file while preserving all your query parameters.

Here's the solution you need:

Add these lines to your .htaccess file on the old domain (old-domain.de):

# Redirect key.php from old-domain.de to newdomain.de, preserving all query params
RewriteCond %{HTTP_HOST} ^www\.old-domain\.de$ [NC]
RewriteRule ^key\.php$ https://www.newdomain.de/key.php [QSA,R=301,L]

Let's break down each part:

  • RewriteCond %{HTTP_HOST} ^www\.old-domain\.de$ [NC]: Ensures this rule only runs when the request is to your old domain (the NC flag makes it case-insensitive, so it works if someone types uppercase letters).
  • RewriteRule ^key\.php$ https://www.newdomain.de/key.php: Explicitly matches the key.php file at the root of the old domain, and redirects it to the same file path on the new domain.
  • QSA flag: Short for "Query String Append"—it automatically preserves all existing query parameters (like id=0000 and ap=ap_id) without you having to manually write them out.
  • R=301: Tells browsers and search engines this is a permanent redirect (ideal for preserving SEO value).
  • L flag: Stops processing any further rewrite rules once this one is applied, preventing conflicts with other rules.

If you only want to redirect key.php URLs where the id starts with 00 (matching your existing rule's behavior):

Add an extra condition to narrow down the redirect:

# Redirect key.php with id starting with 00 from old-domain.de to newdomain.de
RewriteCond %{HTTP_HOST} ^www\.old-domain\.de$ [NC]
RewriteCond %{QUERY_STRING} id=00 [NC]
RewriteRule ^key\.php$ https://www.newdomain.de/key.php [QSA,R=301,L]

Quick testing tip:

When you first set this up, use R=302 instead of R=301—temporary redirects don't get cached by browsers, so you can tweak the rule without worrying about stale cache messing up your tests. Once you confirm everything works as expected, switch back to R=301.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:38:50