Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

linux get url after redirections

curl -Ls -o /dev/null -w %{url_effective} http://google.com
# http://www.google.com/

# We pass in http://google.com, but the URL redirects to http://www.google.com/. Let’s break down the command.
# The -L option tells the curl command to follow the URL redirections. The -s option is for silent mode, which means the command should not output anything to the terminal, while the -o option provides the path that it should send the output to instead of sending it to stdout. In the case above, we’re sending the output to /dev/null.
# The -w option writes out information after the transfer is complete. Moreover, this option has a lot of variables that are set with values and information from the data transfer. The %{url_effective} variable displays the URL that was fetched last. Since we’ve provided the –L option to follow redirections, it’ll give us the final URL.
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #linux #url #redirections
ADD COMMENT
Topic
Name
6+8 =