Score:0

Apache2 symlink - How to use target name and MIME type

cn flag

I just set up an Apache2 server and it works fine. Since this server purpose is to simply serve versioned files, I created a latest symlink which targets e.g. myfile_v1.1.0.ext.

The problem is that when I access the URL http://localhost/latest, the download window shows latest as the filename and application/octet-stream as MIME type.

I would like that when I access this same URL, it shows myfile_v1.1.0.ext as the filename and application/my-app as MIME type.

Is there a way to achieve that?

Many thanks in advance

in flag
Is the symlink pointing to a directory that is hosted on a Samba share?
Dayrona avatar
cn flag
No it does not. It points to a directory which is part of an ext4 filesystem.
Score:0
cn flag

The solution is to simply add a Redirect directive in the Apache configuration file for your website.

Redirect "/latest" "files/myfile_v1.1.0.ext"
Score:0
in flag

One way to do this would be to use an Alias in the Apache configuration. The downside is that you'll need to update this every time there's a release, but the benefit is that you can have a greater degree of control over how the file is handled.

Here is how you can do it:

  1. Edit the Apache .conf file for the site
  2. Add this in the <VirtualHost> section:
    Alias "/download" "/path/to/releases/myfile_v1.1.0.ext"
    <Directory "/path/to/releases">
            Options FollowSymLinks
            AllowOverride All
    
            <FilesMatch "\.(ext|zip)$">
                    Header set Cache-Control "max-age=1209600, public"
                    ForceType application/tar+gzip
            </FilesMatch>
    </Directory>
    
    Note: Be sure to replace application/tar+gzip with the proper content type for the file.
  3. Save the file and restart Apache:
    sudo service apache2 restart
    
    Note: Feel free to switch restart with reload.
  4. Test the url by visiting your.site/download

This has been tested on Ubuntu Server 20.04.3 LTS with Apache 2.4.41

Dayrona avatar
cn flag
It does not really work... The filename still is proposed as `latest` (or `download` in your example). However, thanks to your suggestion, I found a way to got this working. I'll reply to the post with an answer later.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.