Commands.page Logo

How to Specify Referer Header When Using Wget

This guide explains how to specify a referer header when using the wget command on Ubuntu. You will learn the specific syntax required to pass referer information, why this is useful for downloading files from servers that check request origins, and see practical examples of implementing this flag in your terminal commands.

The –referer Flag

To set a referer header in wget, you use the --referer option followed by the URL you want to mimic as the referring page. This tells the server that the request originated from a specific webpage, which is often required to prevent hotlinking or to access protected resources.

Basic Syntax

The standard command structure looks like this:

wget --referer="https://example.com" https://target-url.com/file.zip

Replace https://example.com with the actual referring webpage and https://target-url.com/file.zip with the direct link to the file you wish to download.

Practical Example

If you need to download an image that is protected against direct linking, you might use the following command:

wget --referer="https://www.example.com/gallery" https://www.example.com/images/photo.jpg

This command sends the HTTP referer header indicating the request came from the gallery page, allowing the download to proceed successfully.

Combining with User-Agent

Some servers check both the referer and the user-agent. You can combine flags to mimic a specific browser more closely:

wget --referer="https://www.example.com" --user-agent="Mozilla/5.0" https://www.example.com/file.bin

Using these options ensures your wget request appears as if it originated from a standard browser session on your Ubuntu system.