private function getQuery($siteId, $url = null)
    {
        if (empty($siteId) || !is_numeric($siteId)) {
            throw new InvalidArgumentException('Invalid Site Id To Search By');
        }

        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->_em->createQueryBuilder();

        $queryBuilder
            ->select('r')
            ->from(\Rcm\Entity\Redirect::class, 'r', 'r.requestUrl')
            ->leftJoin('r.site', 'site')
            ->where('r.site = :siteId')
            ->orWhere('r.site is null')
            ->orderBy('site.siteId', 'DESC')//Makes site-specific rules take priority
            ->setMaxResults(1)//Improves speed when no match found
            ->setParameter('siteId', $siteId);

        if (!empty($url)) {
            $queryBuilder->andWhere('r.requestUrl = :requestUrl');
            $queryBuilder->setParameter('requestUrl', $url);
        }

        return $queryBuilder->getQuery();
    }