Forum Moderators: phranque
I am trying to set up a local test server. The test server is currently set up as domain.com.int on my own machine.
The problem is that the test server have lots of hardcoded links going to domain.com / [domain.com,...] so I keep leaving the test server to the production server every time I hit one of these hard links.
Are there any ways to rewrite the links within each page to my test domain on the fly without actually modifying the html?
There are other solution to this issue, however. You can hack up the hosts file on your workstation:
[li] *nix /etc/hosts
[li] Windows 95/98/Me c:\windows\hosts
[li] Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts
[li] Windows XP Home c:\windows\system32\drivers\etc\hosts
...to point domain.com and www.domain.com to the IP address of www.domain.com.int. Note that you'll need to bounce your web browser for this change to take effect, since most browsers cache DNS lookups.
Still another possibility is to set up a proxy server using mod_proxy [httpd.apache.org] to do the right thing. That's probably overkill for this particular situation, tho. =)
Welcome to WebmasterWorld!
Short answer: No. Not unless you 'wrap' all the pages in a script, have Apache call the script, and have the script parse each page and replace the URLs before writing the result to std_out.
Longer answer: You can define the domain name of the production server in your 'hosts' file, and specify the local host (or local server IP address) as its IP address. For requests originating inside your machine, the production server's IP address will be replaced by localhost (127.0.0.1).
Essentially, the hosts file acts a a local 'private' DNS server, and provides the address of the local machine when the real domain name is requested.
On Win XP, the path to the hosts file is: C:\WINDOWS\SYSTEM32\DRIVERS\etc\hosts
Add an entry:
127.0.0.1 www.example.com
Where example.com is your real server's domain name.
Note that your real server will be inaccessible from this machine as a result, so you may want to keep two copies of the hosts file -- one modified and one not -- in order to switch back and forth.
Either that, or modify your on-page links to use server-relative linking, i.e. <a href="/somedir/somepage.html>" instead of <a href="http://www.example.com/somedir/somepage.html">
Jim
It seems like the mod_webfilter is just what I was looking for!
I was considdering to set up a proxy server which rewrote/redirected the urls to my local test site if the refering site was my internal site.
Mod_webfilter seems to provide the easier solution for my problem.