Regex Apache-重定向到同一URL,但附加查询字符串

Regex Apache-重定向到同一URL,但附加查询字符串,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我尝试在Apache上执行一个重写规则,其中重写url以在末尾附加查询字符串: http://example.org/page1.aspx 去 http://example.org/page1.aspx?query=12345 问题是当我应用此规则时: RewriteRule ^\/page1.aspx$ http://example.org.aspx?query12345 [NC,L,R=301] 我最终得到了一个重定向循环 任何帮助都将不胜感激 首先需要使用条件检查查询字符串是否为空:

我尝试在Apache上执行一个重写规则,其中重写url以在末尾附加查询字符串:

http://example.org/page1.aspx

http://example.org/page1.aspx?query=12345
问题是当我应用此规则时:

RewriteRule ^\/page1.aspx$ http://example.org.aspx?query12345 [NC,L,R=301]
我最终得到了一个重定向循环


任何帮助都将不胜感激

首先需要使用条件检查查询字符串是否为空:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?page1\.aspx$ %{REQUEST_URI}?query=12345 [NC,L,R=301]

在测试之前,请确保清除浏览器缓存。

!非常感谢您的快速回复,非常有效。:)