Question about the Redirect directive

I read the detail about the @redirected directive in DocC, and was curious if that’s ONLY metadata in the underlying JSON, or if it extends and creates links in existing archives.

For example, if I’m moving an article to a new URL, and hosting on GitHub pages, but I want to have the archive host something that redirects to the new location to preserve the old links for external folks, does that work?

I tried an experiment where I did just that - adding in

@Redirected(from: "oldlocation")

and then ran the preview for the catalog, but using an assembled url that referenced that referenced the original location just provides a 404.

The docs infer that any redirection capabilities are only supported if the hosting provider adds the redirects, is that accurate?

Yes, the documentation is correct.

DocC treats the redirect values as opaque passthrough information that is only written to an optional metadata file (that’s not created unless the caller passes additional flags (as mentioned in the documentation)). DocC itself never inspects these values or does anything with them. That’s why the documentation says that it doesn't matter if the values are relative or absolute:

You can write either relative redirect values or absolute redirect values in the markup depending on what information you need when setting up HTTP “301 Moved Permanently” redirects on your web server.

IIRC, I believe that it's intentional that the preview server doesn't follow these redirect values because that could lead to developers accidentally failing to or forgetting to set up redirects on their web server because they experienced it working locally and thought that it would automatically work on their web server / hosting provider as well.

1 Like