How to tell wget to use the name of the target file behind the HTTP redirect

redirectredirectionshellunixwget

Let's a consider link such as htttp://www.mysite.net/download.php?id=267 that redirects to htttp://www.mysite.net/downloads/myfile.tar.gz

If I execute 'wget "htttp://www.mysite.net/download.php?id=267"' wget will happily download and save the result in a file named "download.php?id=333". Naming this file "myfile.tar.gz" would have made much more sense.

There is of course the workaround of using 'wget -O myfile.tar.gz "htttp://www.mysite.net/download.php?id=267"' but this is not what I want : I want wget to do the right thing automatically.

Is there any anyway to tell wget to use the name of the target file behind the HTTP redirect ?

I there any other similar tool that would do that ?

Best Answer

wget --trust-server-names=on htttp://www.mysite.net/download.php?id=267

Or option trust-server-names in ~/.wgetrc.

It may be a security risk if the HTTP redirect goes to ../../../../../../../../../../../../etc/passwd