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
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.
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.
SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 195,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.