A starting /
in a path, like /whatever
, means that the thing referenced is found at the root, the topmost level of the hierarchy of a filesystem.
But, since a webserver is involved, this root has a slightly modified meaning:
/media/dale/whatever
is normally interpreted (by you and the OS) as something referencing the root of the operating systems' physical filesystem.
But whithin the context of a (HTML) document being served by a webserver, /
will mean the "public document root". It means the slash in localhost/
And since your localhost
maps to /var/www/html/
on the OS' physical filesystem, when your served document refers to /media/dale/whatever
, it will end up being interpreted as /var/www/html/media/dale/whatever
, which is not there.
You could either put your served files within /var/www/html/
, or configure your server to serve the content of /media/dale/
instead of /var/www/html/
. (In this latter case you would need to put also your index.html
in /media/dale/
.)
Another idea is —though I have never tried this, so I don't know if it's even possible— but you could experiment with leaving the server config and the location of the files as is, and try using a symlink to point to the file, or at the containing directory, from your normal server document root...
(In the meanwhile, I found this. So you need to enable symlinking in Apache throgh FollowSymLinks
, while also applying sufficient access permissions on the target.)
Update:
I had one more idea, but this is also something that I haven't tried, so I'm not sure if feasible or not.
The Apache webserver has a feature called "virtual hosts", which makes it possible to simultaneously serve multiple locations from the filesystem — not just /var/www/html/
, but further other locations as well.
Here is how:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04
Now you could try a hack where you would define a new virtual host to point at /media/dale/
. The relevant part of the doc starts from Step 4. I don't know whether this would be trivial to achieve or not, but I would look into it.
If this virtual host trick would be possible, then in your HTML file, you could refer to the ServerAlias
value of this virtual host when you link to your media file (in the src=""
attribute). It's like as if you would be pointing to another, additional, external webserver. As a result, your browser would bring together the content from two different sources: the HTML document itself would arrive out of /var/www/html/
(according to your current config, accessed from the browser as "localhost"), while the media files would arrive from the virtual host server alias. Unless I'm unaware of some gotcha, Apache should be happy to serve both of them to the browser.