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
You'll want to ask this question in the SAM forum: https://thwack.solarwinds.com/product-forums/server-application-monitor-sam. Move it there, and we may already have answer.
Use Javascript:
window.location.replace('http://example.com');
It’s better than using window.location.href = ‘http://example.com’;
Using replace() is better because it does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.
If you want to simulate someone clicking on a link, use window.location.href
If you want to simulate an HTTP redirect, use window.location.replace
You can use assign() and replace methods also to javascript redirect to other pages like the following:
location.assign("">http://example.com");
The difference between replace() method and assign() method(), is that replace() removes the URL of the current document from the document history, means it is not possible to use the “back” button to navigate back to the original document. So Use the assign() method if you want to load a new document, and want to give the option to navigate back to the original document.
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 200,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.