Jump to content

Testing mod_rewrite on internal LAN


Michael Daly

Recommended Posts

I have two virtual hosts on a single Apache 2.2 web server. I also have two machines as:

 

1 - Production. 192.168.123.1 - firewall routes real traffic to this one with domain names e.g. realdomain.foo/bunch/of/stuff. I can't touch this server.

 

2 - Test. 192.168.123.2 - I test on this.

 

The test machine gets web accesses in the form of 192.168.123.2/bunch/of/stuff. Since I need to do rewrite processing on the [HTTP_HOST], I'm not getting the domain, just the IP.

 

How do I spoof the test server so that the rewrite can be tested with realdomain.foo/bunch/of/stuff instead of 192.168.123.2/bunch/of/stuff?

Link to comment
https://forums.phpfreaks.com/topic/38037-testing-mod_rewrite-on-internal-lan/
Share on other sites

  • 2 weeks later...

I figured out a solution that seems to work (so far).  In the virtual host rewriting section, I start with:

 

# Do nothing rewrite rule that sets the environment variable.

RewriteRule .* - [E=USE_HOST:realdomain.foo]

 

... bunch of stuff ...

 

#  Test the host and rewrite accordingly

  RewriteCond %{ENV:USE_HOST}  ^realdomain\.foo$      [NC]

 

This lets me use the faked host instead of the IP for testing on the LAN.  When I want to do final test (and move code to production) in a production level environment, I change the first rewriterule to:

 

  RewriteRule .* - [E=USE_HOST:%{HTTP_HOST}]

 

Now I have the same code with the host as it comes in from the 'net without touching the rest of the code (and inadvertently breaking it).

 

Not perfect, but acceptable for now.

And a better solution still is to edit the "hosts" file (\WINDOWS\system32\drivers\etc\hosts - no extension) and put the domain in with the LAN address.

 

Windows uses HOSTS as a kind of DNS cache.  Just make sure you remove the entry from hosts when you're done or you'll never get the real IP.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.