如果用户手动更改网址,如何将用户重定向到主页?

Let's say the user is in the page --> mysite.com/product.php?id=5 and he manually removed the ?id=5 and r=the url became this way--> mysite.com/product.php

How can I redirect him to the homepage?

Just check to see if the id is missing from the query string. If so, do the redirect.

if (!isset($_GET['id']) || empty($_GET['id'])) {
    //redirect
}

If you still want the page to be accessible if Parameters are set use this method:

if(!isset($_GET)){
    header("Location: http://mysite.com/");
    exit;
}

Check to see if no variables have been passed to the page, and then redirect accordingly.
exit after the Header to be sure that no text is sent to the browser that will break the header.

If this will become a dead page, use a 403:

header ('HTTP/1.1 301 Moved Permanently');
header ("Location: http://mysite.com/");