基于特定查询字符串重定向

Redirect based on a specific query string

如果有给定的查询字符串,我想要实现的是重定向我的页面。

比如我想重定向

http://example.com/?taguid=CSTAGUID3fffd76e5e7db1369860ad8e0e5ed3fa

http://example.com/map/?taguid=CSTAGUID3fffd76e5e7db1369860ad8e0e5ed3fa

所以我想传递这个 taguid 参数,但是在 map 目录中。

我试过这个:

RewriteCond %{QUERY_STRING} (^|&)taguid= [NC] 
RewriteRule ^ /map/\?taguid= [L,R=301]

有两个问题。

有人可以帮我解决这个问题吗?

您可以使用来自 DocumentRoot.htaccess 的此规则:

RewriteCond %{QUERY_STRING} (^|&)taguid= [NC] 
RewriteRule ^/?$ /map/ [L,R=301]

QUERY_STRING 会自动转移到目标 URL,无需捕获和传递相同的查询字符串。