Direct URL to local file via the host file

6

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.

maxedison

Posted 2013-02-26T15:42:57.830

Reputation: 229

Actually, you're not mapping URLs at all. You're just resolving a hostname. – ckhan – 2013-02-26T15:49:11.563

What are you trying to do? Do you actually want to display a certain HTML page when attempting to access Google or do you just want to display a local HTML file in your browser? – Dennis – 2013-02-26T15:55:04.930

@ckhan thx. i'm not suprised that my vocab was off on this one – maxedison – 2013-02-26T16:15:24.983

Answers

12

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:

TFM

Posted 2013-02-26T15:42:57.830

Reputation: 4 243

Thanks for both answering my question and helping clear up my vocab ;) – maxedison – 2013-02-26T16:14:40.537