Say if I put www.abc.com in the browser, the browser automatically gets redirected to www.xyz.com. I need to get that redirect url from server side. That is, if www.abc.com returns a redirect url www.xyz.com, how can I request this redirect URL (www.xyz.com) from the original URL (www.abc.com)?
Type "cache:sitename.com" in the address bar of Chrome and press "Enter" where "sitename" is the URL that is generating the redirect. This will show you a cached version of the site on which you can use the Inspect Element pane to find and capture the redirect URL.
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start with 3 , and a Location header holding the URL to redirect to. When browsers receive a redirect, they immediately load the new URL provided in the Location header.
If everything is configured properly, it takes about 30 minutes to start working. Read more about different types of redirects.
A redirect is an Http response sent to the client. The response contains an Http Header called Location which must contain an absolute url. The client then issues a GET request against this url. So, no, POST is not an option.
Here's a snippet from a web crawler that shows how to handle redirects:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.AllowAutoRedirect = false; // IMPORTANT
webRequest.UserAgent = ...;
webRequest.Timeout = 10000; // timeout 10s
// Get the response ...
using (webResponse = (HttpWebResponse)webRequest.GetResponse())
{
// Now look to see if it's a redirect
if ((int)webResponse.StatusCode >= 300 && (int)webResponse.StatusCode <= 399)
{
string uriString = webResponse.Headers["Location"];
Console.WriteLine("Redirect to " + uriString ?? "NULL");
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With