基于查询参数失败的 HTAccess 重定向?

HTAccess redirect Based on Query Parameter Fails?

我正在尝试根据查询字符串参数 "ref" 的存在重定向 (HTAccess) URL。仅当前缀文件夹 "TMP" 和页面名称 "domain.html" 存在时才重定向。 问题是重定向有效,但查询字符串没有被传递

例如 http://www.olddomain.com/TMP/domain.html?ref=website-reference.com

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/TMP/domain\.html$
RewriteCond %{QUERY_STRING} ^ref=([0-9]*)$
RewriteRule ^(.*)$ http://www.newdomain.com/?ref=%1 [R=301,NE,NC,L]

您可以使用:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^ref=
RewriteRule ^TMP/domain\.html$ http://www.newdomain.com/ [R=301,NE,NC,L]

使用相同的查询字符串。