Site icon Hip-Hop Website Design and Development

add_rewrite_rule refuses to function

I am trying to create a custom redirect on my local machine using MAMP. From the WordPress codex I have the following code as a simple starting point. No matter what I try I cannot get this simple solution to function as expected. I am running the latest version of WordPress, I have saved the permalinks to flush the redirects and changed the theme to eleminate this as variable. My xampp has mod_rewrite enabled.

I simply want to redirect: http://example.com/?p=95 to http://example.com/leaf/95

The code is as follows:

function custom_rewrite_basic() {
add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
    
      }
      add_action('init', 'custom_rewrite_basic');

My htaccess is the basic wordpress version and I am not using any plugins in my build.

Any help will be greatly appreciated.