0

I have a line in /etc/hosts to rewrite something to localhost:

127.0.0.1   foo.bar

Can the equivalent be done without modifying the hosts file, somehow with an Apache rewrite or something like that?

user3761308
  • 103
  • 2

1 Answers1

2

No. They are for different purposes and work on a completely different protocol.

  • The /etc/hosts affects client behavior on which IP it should resolve instead of using DNS.
  • The Apache virtualhost configuration defines what the server does with the HTTP Host: header.
  • The Apache mod_rewrite does URL rewriting after the connection is already established & the correct virtualhost is decided. It can rewrite within filesystem or perform an external redirect.
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129