<- Back to the HOWTO section

How to avoid master_sites redirects

  • Audience: Portfile authors
  • Requires: MacPorts >=2.0


master_sites should usually be specified in such a way that HTTP redirects are avoided. This not only reduces network traffic and server load but also lets the user start their download more quickly. This how-to currently addresses only SourceForge but similar techniques can be used for any other site.


In addition to the aforementioned general reasons for avoiding redirects, it's especially important for files hosted at SourceForge. For all ports, MacPorts tries to download from a server near to the user (measured by ping time). SourceForge has a network of mirror servers, of which MacPorts maintains a list. But if the server MacPorts has chosen to use issues a redirect, it might redirect to a different server which might have a worse ping time, which we want to avoid.

Hopefully, the following example, using mediainfo version 0.7.60, will illuminate the process. The SourceForge home page for mediainfo is Initially, just specifying 'sourceforge' in the portfile under development worked to retrieve the distfile.

master_sites  sourceforge

The log for 'port fetch' showed:

DEBUG: Executing org.macports.fetch (mediainfo)
--->  MediaInfo_CLI_0.7.60_GNU_FromSource.tar.bz2 doesn't seem to exist in /opt/local/var/macports/distfiles/mediainfo
--->  Attempting to fetch MediaInfo_CLI_0.7.60_GNU_FromSource.tar.bz2 from

Use curl -IL to check for redirects. In this case the output indicated redirects to a final address of:


To improve the master_sites parameter, extract the bit: project/mediainfo/binary/mediainfo/0.7.60 (and replace "0.7.60"--the version number in this case--with ${version}). Thus you have:

master_sites  sourceforge:project/mediainfo/binary/mediainfo/${version}

In the event that the URL had included "0.7" (and not "0.7.60") you would want to define and employ the ${branch} variable instead of ${version}.

Pat yourself on the back--you're done!

<- Back to the HOWTO section

Last modified 11 years ago Last modified on Aug 6, 2013, 9:43:50 PM