Does your example contain real code, or have you just included someething that's made up to make the question simpler to ask?
It seems a strange thing to do - providing the user with a search box and then, as soon as they start typing, redirect them to another page.
If you are doing a search, and you only want the earch page to be triggered from a form, rather than by the user typing in the URL, then consider setting the form method to 'POST' and checking for this on the search page. If the method is 'GET', then the URL was typed manually, and you can redirect back to the original page.
Admittedly, this technically violates the recommendations for the use of 'POST', which should only be for operations that change information, rather than 'GET' which should be used when asking for information. However, this is one occasion where this might be excusable.
Another approach that you could use is to generate a unique key of some kind, and store this in a hidden field of the form, the check for this before deciding whether to redirect to the original page. This would require some kind of reliable key generation scheme, making it slightly trickier, but not impossible.