Commands.page Logo

How to Configure Wget to Follow Redirects on Ubuntu

This article provides a quick guide on handling HTTP redirects when using the wget command-line utility in Ubuntu. It explains the default behavior of the tool regarding redirects and identifies the specific option used to control or increase the number of redirects wget will follow during a download session.

By default, wget is configured to follow HTTP redirects automatically without requiring any additional flags. When you run a standard wget command, it will pursue up to 20 redirections before stopping. If you need to modify this behavior or ensure wget follows a specific number of redirects, you use the --max-redirect option. This flag allows you to set the maximum number of redirects the program should follow before aborting the download.

To use this option, append --max-redirect=number to your command. For example, to allow wget to follow up to 5 redirects, you would run the following command in your Ubuntu terminal:

wget --max-redirect=5 https://example.com/file.zip

If you encounter a situation where wget is not following redirects, it is likely because the limit has been reached or set to zero in a configuration file. Increasing the value with the --max-redirect flag resolves this issue. There is no need for a specific “enable” flag like -L in curl, as the functionality is active by default in wget.