SAM TEMPLATE to monitor 301 redirect

Looking to create a SAM TEMPLATE to monitor when a 301 redirect is not working when forwarding from a website.  Any help or advice would be greatly appreciated.   TIA

Parents
  • Try this on php.

    <?php
    $url = "http://example.com"; // The URL to monitor

    // Send a request to the URL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    // Check if the response code is 301
    if ($responseCode === 301) {
        echo "The 301 redirect is working correctly.";
    } else {
        echo "The 301 redirect is not functioning as expected. Response code: " . $responseCode;
    }
    ?>

    Set  CURLOPT_FOLLOWLOCATION to true, cURL automatically follows any redirects. We then retrieve the response code using curl_getinfo() and compare it to the expected value (301 in this case). Based on the result, we output a message indicating whether the redirect is working correctly or not.

    i hope this might help you.

     

Reply
  • Try this on php.

    <?php
    $url = "http://example.com"; // The URL to monitor

    // Send a request to the URL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    // Check if the response code is 301
    if ($responseCode === 301) {
        echo "The 301 redirect is working correctly.";
    } else {
        echo "The 301 redirect is not functioning as expected. Response code: " . $responseCode;
    }
    ?>

    Set  CURLOPT_FOLLOWLOCATION to true, cURL automatically follows any redirects. We then retrieve the response code using curl_getinfo() and compare it to the expected value (301 in this case). Based on the result, we output a message indicating whether the redirect is working correctly or not.

    i hope this might help you.

     

Children
No Data