Question: How do I redirect this page URL, `http://localhost/wordpress_rnd/?page_id=2`, to the home URL, `http://localhost/wordpress_rnd/`, without using any plugins?

Answer: 
The correct way to do this is using the [`template_redirect`](https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect) hook by adding a function to your `functions.php`:

```
function redirect_to_home() {
  if(!is_admin() && is_page('2')) {
    wp_redirect(home_url());
    exit();
  }
}
add_action('template_redirect', 'redirect_to_home');

```
```
add_action( 'init', function() {
    if ( 0 === stripos( $_SERVER['REQUEST_URI'], '/page_id=2' ) ) {

       wp_redirect( home_url(), 301 );
       exit;

    }
}

```

Put this code in a mu-plugin or in your theme's functions.php file