How to get correct website url from a redirect in r?

by filiberto , in category: Third Party Scripts , 7 months ago

How to get correct website url from a redirect in r?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 6 months ago

@filiberto 

To get the correct website URL from a redirect in R, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(httr)

# Make a GET request to the original URL
response <- GET("https://example.com/original-url", 
                follow_redirects(follow = FALSE))

# Get the final URL after following all redirects
final_url <- url_absolute(response$url)

print(final_url)


This code makes a GET request to the original URL while disabling automatic redirect following. It then retrieves the final URL after all redirects have been followed using the url_absolute function. Finally, it prints the correct website URL.

Related Threads:

How to redirect website url to https:// using .htaccess file?
How to get final redirect url in php?
What is the correct way to get innerhtml of iframe?
How to get correct auth0 bearer token?
How to redirect non-www to www on my wordpress website?
How to redirect dynamic url back to source url in wordpress?