Skip to content

Conversation

@randytate
Copy link

I wanted to be able to tell if a URL was redirected due to OpenGraph/Canonical tags ... or if it truly was a redirect.

    $url = $row["Destination URL"];

    // Not Found, until we determine otherwise
    $row["URL Status"] = "Not Found";
    $url_result = $resolver->resolveURL($url);

    if ( $url_result->didConnectionFail() ) {
        $row["URL Status"] = "Connection Failure";
    }
    else if ( $url_result->didErrorOccur() ) {
        $row["URL Status"] = "Error Occured";
    }
    else if ( $url_result->getHTTPStatusCode() == "404" ) {
        $row["URL Status"] = "Not Found";
    }
    else if ( $url_result->isStartingURL() ) {
        $row["URL Status"] = "OK";
    }
    else if ( $url_result->redirect30xCount() ) {
        $row["URL Status"] = "Redirect (" . $url_result->redirect30xCount() . " times)";
        $row["Redirect URL"] = $url_result->getURL();
    }
    else {
        $row["URL Status"] = "Not Canonical";
        $row["Canonical URL"] = $url_result->getURL();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant