Get Caddy to follow .lnk files not serve them

1. The problem I’m having:

I’m using Caddy as a simple file server.
The folders it’s sharing are from a Windows file share, mounted on a linux server via an fstab entry.

It works fine, except Windows shortcut files show up as .lnk
When you click to download, you get the actual .lnk file, with .download appended to the file name.

I’d like it to follow the shortcut, not literally serve it.

2. Error messages and/or full log output:

A sample from the log when it happens.

2024/09/18 13:15:40.908 DEBUG   http.handlers.file_server       opening file    {"filename": "/var/www/html/shares/forms/Accounts Payable Forms/AP-1014 - Vendor Entry Form.ott.lnk"}

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

binary download, dropped in folder

a. System environment:

currently CentOS 7

b. Command:

./caddy_linux_amd64 file-server -v --browse --reveal-symlinks -r /var/www/html/shares -l 0.0.0.0:8080

Howdy @furicle, welcome to the Caddy community.

I don’t know that Caddy has any options available to do this. It would involve some special handling: opening the file, reading the text content, resolving it to a filesystem path, and attempting to find that.

Caddy would also need to translate from the Windows filepath of the link to whatever filesystem it’s actually reading from e.g. the CIFS mount, which the link file might not account for. For example, the link might be a UNC path (e.g. \\host\path\to\file.ext) that doesn’t make any sense to a Linux client that mounted the CIFS share into a different folder (UNC paths like this are a Windows-specific feature). It’s not really feasible without some heavy lifting from external tooling.

The best answer I can give you matches this Stack Overflow link from 2010, which is to delete the .lnk file and create a symbolic link or a junction instead, which is a filesystem based link method any web server can actually understand.

1 Like

Thanks for the detailed reply.
That’s pretty much what I thought as well, but I was hoping :slight_smile:

A soft or hard link would work, but these are changed by end users from time to time, and I don’t think they’d be reliable completing that extra step. Maybe I could rig something up with a file change monitor and a script…

I was really hoping to just have web and windows file sharing from the same set of docs, so they’re always in sync.

More thought needed

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.