Question: 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?

Answer: 
**Option 1: Using `file://` links**

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

```
file:///path/to/folder

```

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`](https://docs.python.org/2/library/simplehttpserver.html) 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.](https://gist.github.com/willurd/5720255)

---

**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/>

UPDATE:
=======

After you added your *specific need* in the comments, I would recommend reading [this page](http://kb.mozillazine.org/Links_to_local_pages_do_not_work) 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.
First you need to install LAMP stack or just web server as: [Apache](https://httpd.apache.org/), [Lighttpd](https://www.lighttpd.net/) or [Nginx](https://nginx.org/). Then you must configure your web server and enable [HTTPS](https://en.wikipedia.org/wiki/HTTPS), if you really need **s**ecure connection, not just [**HTTP**](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol).

---

Here you are few HOW-TOs about Apache2:

* How-to [install LAMP](https://askubuntu.com/q/34/566421), see also [the official documentation](https://help.ubuntu.com/community/ApacheMySQLPHP).
* How-to [configure Apache2 Virtual Hosts](https://askubuntu.com/a/811416/566421).
* How-to [open port 80/443 (HTTP/HTTPS) into the firewall](https://help.ubuntu.com/lts/serverguide/firewall.html).
* How-to [enable a free certificate from Let's Encrypt](https://askubuntu.com/a/900433/566421).
* How-to [increase your web server's security](https://askubuntu.com/a/922144/566421).