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
  • 249
  • Actually, you're not mapping URLs at all. You're just resolving a hostname. – ckhan Feb 26 '13 at 15:49
  • 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 Feb 26 '13 at 15:55
  • @ckhan thx. i'm not suprised that my vocab was off on this one – maxedison Feb 26 '13 at 16:15

2 Answers2

12

No you cannot.

The hosts file is for mapping hostnames to IP addresses (and not "URLs"), especially when a DNS Server is not available or when 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
  • 4,263
0

actually you can very easily, all you have to do is start a local webserver and include your local html in said server. that way when you redirect to 127.0.0.1, your "local file" is displayed. this can be used as a parental control feature or a way of blocking certain websites on company computers

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community May 09 '22 at 14:02
  • The question specifically states "without running a local server". – Donald Duck May 09 '22 at 15:24