simple add_rewrite_rule not working


I’m trying to redirect https://example.com/register to https://example.com?mode=register

I have tried the following code

add_action( 'init', 'redirect_urls' ); function redirect_urls(){     add_rewrite_rule('/register/', 'index.php?mode=signup', 'top' ); } 

But it does not work or redirect at all. How do I fix this?