'How to redirect URL with query string without name to new url

I have these URLs

https://example.com/team?1892
https://example.com/team/?1892

which I need to redirect to

https://example.com/team/whatever/

How can I do that? I only find redirect solutions where the query strings have names. Thanks for suppport!



Solution 1:[1]

This should do it:

RewriteCond %{QUERY_STRING} ^1892$
RewriteRule ^/?team/?$ /team/whatever/ [R=301,L,QSD]

In English: if the query string is exactly "1892" and the URL path is "/team/" (with optional slashes), then redirect it to "/team/whatever/" without preserving the query string, using a 301 permanent redirect.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1