Direct URL to local file via the host file

hosts-file

I know I can map URLs to other URLs via the host file, but can I map a URL to a local html file on my hard drive without running a local server and loading the html file through there? Something like:

C:\myTestFile.html    www.google.com

I'd like to know how to do this on both Mac and Windows.

Best Answer

No you cannot.

The hosts file is for mapping hostnames to IP addresses (and not "URLs"), expecially where a DNS server is not available, or where there's a need to override entries in a DNS server.

A file has no hostname/IP address, thus, what you're asking is not possible.

If you want to read more on this subject:

Related Question