Testing mod_rewrite on internal LAN

Using a single web hosting account to host multiple sites

Testing mod_rewrite on internal LAN

Postby Michael Daly » Sun Feb 11, 2007 8:50 am

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?
Michael Daly
 
Posts: 4
Joined: Sun Feb 11, 2007 8:42 am

Postby richardk » Sun Feb 11, 2007 2:53 pm

If you're inside the LAN, then you could make a record in your hosts file to send requests to realdomain.foo to 192.168.123.2.

Other than that i don't think you can. Mod_rewrite can't change what the router/firewall does; it can only work once the request gets to the server.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Michael Daly » Mon Feb 19, 2007 1:25 pm

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 ...

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.
Michael Daly
 
Posts: 4
Joined: Sun Feb 11, 2007 8:42 am

Postby Michael Daly » Wed Feb 21, 2007 7:11 am

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.
Michael Daly
 
Posts: 4
Joined: Sun Feb 11, 2007 8:42 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 12 guests

cron