Ubuntu – Make URL point to local folder


I have a URL to be mapped, on my Ubuntu 16.04 machine, to a local folder.

E.g. I need https://domainxxx.xxx to point to /home/user/folder.

My specific need is to include domainxxx.xxx/file.js not as the real 'file.js' on the remote server, but as /home/user/folder/file.js which is on my machine.

I've read this is not possible with an entry in /etc/hosts. How can I do this?

Best Answer

Option 1: Using file:// links

You can point your browser to any folder on your computer using


A list of files should show up, similar to a File Browser. Web Browsers can also parse .html files, show images, play some video formats, open text and xml files from your local machine. Just point your browser to file:///path/to/file.ext.

Option 2: Running an HTTP-Server

If you need to parse files other than .html (e.g. php files) or need to access them from another computer, you need to run an http server like apache, nginx or Python SimpleHTTPServer on your local machine. Then you can use http:// and if configured also https:// URLs.

Here is a nice list of Instant HTTP Server options.

Example: Start an Instant http-Server using Python and SimpleHTTPServer

Python 2.x:

cd /home/user/folder && python -m SimpleHTTPServer 8082

Python 3.x:

cd /home/user/folder && python3 -m http.server 8082 

Then open your preferred browser: http://localhost:8082/


After you added your specific need in the comments, I would recommend reading this page why local links inside http pages are not allowed. Included is also a workaround (overriding the security policy using NoScript).

For security purposes, Mozilla applications block links to local files (and directories) from remote files. This includes linking to files on your hard drive, on mapped network drives, and accessible via Uniform Naming Convention (UNC) paths. This prevents a number of unpleasant possibilities

I see three options:

  • Use an (Instant) HTTP Server, then you can include http://localhost:8082/file.js directly.
  • Overrde Firefox security policy and use a file:// link (I would not do it when other options exist)
  • Let the Server access the file via http, smb or ssh connection to serve it directly (if you're behind a router or firewall, you need to take care of port forwarding). This is quite complicated to achieve, but is the only option that enables access from other machines (only while your computer is online).

Note: For better answers, always write the question as specific as possible from the beginning.

Related Question