|Do you know where your variables are?|
Simulating a Two-Domain Website on the Localhostby shlomif (Beadle)
|on Oct 31, 2005 at 17:18 UTC||Need Help??|
My homesite spreads across two domains: http://www.shlomifish.org/ and http://vipe.technion.ac.il/~shlomif/. Now, some pages are found on one domain and others on the other, with cross-links between the two places. Why it is so I'll tell later on, but meanwhile let's get to my problem.
The site is a static HTML one. I am building it from its source on my local machine, and then updating the live copies of both machines using rsync. I have both domains served on my localhost web-server under two different aliases, so I can test them there.
The problem is that they have the cross-links to the other domains and as a result point to the real pages on the Internet instead of the ones I've compiled and placed on my hard disk.
So what do we do? After putting up with this behaviour for a long time, I decided that I'd like the links on one domain to point to their local alias instead of their full web address. I decided that I needed a way to serve the files in a special way that will re-write their text. I investigated various Apache modules - mod_rewrite, etc. but was told they don't do that. The best I could do using Apache was to write an output filter, but that was incredibly complicated.
So, instead I opted to write two Perl CGI scripts that will serve the files from the directory tree that contains them as modified by the simple transformations of both "http://www.shlomifish.org/" to "http://localhost/sites/hp/shlomif/" and "http://vipe.technion.ac.il/~shlomif/" to "http://localhost/sites/hp/vipe/".
I ended up writing it as a module and two very simple files. The module is:
And the files are:
The code of ShlomifServe.pm is freely available under the MIT X11 License, but will require some tweaking by someone who wishes to use it.
Running it as CGI was somewhat sluggish, but running it under mod_perl made it very responsive on my computer. Using this script, the original HTML, which needs to be uploaded to the server remains intact, while I can browse the two local domain sites at ease as served by the script.
Appendix: why the Two Domains?
In my last workplace before I started my B.Sc. studies in the Technion, I was allowed to host my personal site on the company's web-site under the /~shlomi/ alias. Later on, when I joined the Technion and stopped working at this company, I placed it under my account on the Technion's undergraduates' server. So the address was http://t2.technion.ac.il/~shlomif/. It was still plain HTML pages, without too much style and without a consistent look and feel.
After a while, I also got an account on vipe.technion.ac.il which is a server maintained by the students. I started setting up some pages there, because I had a very limited quota on t2. So, then I started having links from one place to the other.
Shortly before the end of my undergraduate studies, knowing that my account on t2 is going to be terminated, I realized that I need a more permanent location for the homepage. So I started hosting it on a different server first at shlomif.il.eu.org, which ended up causing me a lot of DNS problems and then on www.shlomifish.org. (which is a domain I bought). I changed all of the links I could (such as the one in my E-mail signatures) to point to the new place. Eventually, Google and other search engines adapted.
Meanwhile, however, there were still many resources remaining under vipe.technion.ac.il, so I kept them there, so the links won't be broken. The fact that my homesite spans two domains affected the feature set of technologies I created to maintain my site like Latemp or HTML-Widgets-NavMenu.