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.

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

2 Answers 2

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:

1
  • Thanks for both answering my question and helping clear up my vocab ;)
    – maxedison
    Feb 26, 2013 at 16:14
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

2
  • 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 Bot
    May 9, 2022 at 14:02
  • The question specifically states "without running a local server". May 9, 2022 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .