'Redirect to a URL if query string is not completely given

I wanted to frame Rewrite rule condition for Apache if the query string is not completely available. Below is the scenario:

This is the working URL format -

https://<base_url>/redirect_uri#state=<value>&token=<value>

If the URL is coming like https://<base_url>/redirect_uri, I wanted to redirect to the login page.

I tried as below which is not recognizing the parameter

RewriteCond %{QUERY_STRING} !^#state [NC]
RewriteRule ^/redirect_uri$ https://<base_url>/login [R=301,L]

Please help me to correct the condition to recognize the parameter



Sources

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

Source: Stack Overflow

Solution Source