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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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