Using PHP’s strpos to test a URL

I need to redirect old URLs that are attached to a domain that has been re-purposed for a new project. These old URLs have become an obstacle in achieving decent search engine ranking. I need to detect whether the URLs contains a phrase or word and redirect with a 410 header status if the phrase is found, if the phrase is not found I then redirect to 404 soft redirect. In PHP I can utilize PHP’s native function strpos()

$url = $_SERVER['REQUEST_URI']; //$url can be any string

if (strpos($url,'') !== false) {
    // redirect to 410
} else {
    // redirect to 404

Need a website, consultation or customisation? Let’s speak