'Rewrite and redirect with php variable with rewrite conditions

I want to use rewrite rule to redirect this specific URL: https://example.net/?myvar=none

to: https://example.net/test-page-to-redirect/

It's very important only redirect this specific url, because for example, this url is correct https://example.net/?myvar=111

I'd tried several options without results, lastest i try:

RewriteCond %{QUERY_STRING} myvar=none
RewriteRule .* /test-page-to-redirect [R=302]

Thanks you for your help



Solution 1:[1]

You may use this redirect rule:

RewriteCond %{QUERY_STRING} ^myvar=none$
RewriteRule ^$ /test-page-to-redirect/? [R=302,L]

Make sure to clear your browser cache before testing this change.

By using anchors in RewriteCond and in RewriteRule we are making sure that only given URL matches nothing else.

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 anubhava