Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Last active March 17, 2020 19:11
Show Gist options
  • Save blackrobot/0812dc9e26ef2daa7489a53c4352cde0 to your computer and use it in GitHub Desktop.
Save blackrobot/0812dc9e26ef2daa7489a53c4352cde0 to your computer and use it in GitHub Desktop.

Redirect To File Download

To use this, replace all of the placeholder content in 01.template.html with the actual file path and name.

Then save the resulting html file as index.html to be used as the S3 bucket index as well as the error page for redirects.

Example

Using an example file named example.txt, I've created an example of what the filled in template might look like in 02.filled-in-example.html.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Replace the title here with whatever you want. You can also delete this line, it's a comment. -->
<title>Downloading file "example.pkg"</title>
</head>
<body>
<!-- Put whatever text you want inside the `p` tag, or you can delete it entirely. -->
<p style="margin:20% auto;font-family:sans-serif;font-size:20px;text-align:center;color:#444;">
Downloading file "example.pkg"
</p>
<script>
window.onload = function() {
/* Change the URL here to be whatever you want. If the file is on the same domain
this can be a relative URL. For example, if this `index.html` file is located at
`https://example-url.com/index.html`, then best practice for redirecting to the
file would be to use the relative url:
window.location.href = "/example.pkg"
This comment can be deleted from the final file.
*/
window.location.href = "https://example-url.com/path/to/example.pkg"
}
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Downloading file "example.txt"</title>
</head>
<body>
<p style="margin:20% auto;font-family:sans-serif;font-size:20px;text-align:center;color:#444;">
Downloading file "example.txt"
</p>
<script>
window.onload = function() {
window.location.href = "/example.txt"
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment