Proxyless Domain Proxy

The Premise

I have a site for a school project that I’m hosting on a school server. I want to keep it hosted there for reliability/accountability reasons (i.e. if their servers go down on the day of a presentation it’s their fault; if I use my discount host, it’s my fault), but I’d like to use a custom domain.

Neither school nor my host seem to allow proxies (RewriteRule ^/~nliebman(.*)$ http://localchi\.com$1 [P] doesn’t work), so there had to be a different solution.

The Solution

First I need to credit this to pippo over at Dev Shed.

Rather than having Apache rewrite the school URL to my own URL, the trick is to have PHP do all the work, and simply rewrite the PHP file’s URL (on my server) to show the filename from the school server.

On my server, I created the following PHP file, called getRemote.php:

<?php
readfile( "http://projects.si.umich.edu/~nliebman/".$_SERVER[ 'REQUEST_URI' ] );
?>

Then, I added this rule to my .htaccess:

RewriteCond %{REQUEST_URI} !/getRemote.php [NC]
RewriteRule ^(.*)$ /getRemote.php [L]

I didn’t need to touch anything on the school server. I do take a performance hit since my server needs to get the content from the school server before serving it to me, but it’s pretty light-weight stuff, so it’s worth it for the pretty URL.

Comments

4 Responses to “Proxyless Domain Proxy”

  1. Spike on October 5th, 2008 12:00

    Thanks for sharing the nifty trick. Does this work only for files in that directory or in nested directories from the Umich servers?

  2. Hung on February 7th, 2009 17:07

    But if the point is to have the reliability of the school’s server, then your solution fails when your server goes down and it can’t process php.

    Though you could failsafe to the school’s server. But a visitor to your website wouldn’t know where the real files are being served.

  3. School Proxy on April 11th, 2009 10:38

    THanks for the little code man, I got a similar problem with my hosting, I think now it’s going to be solved.

  4. Noah on April 16th, 2009 10:26

    I just want to point out that I had some trouble with Firefox recognizing CSS files as CSS using this method. I even manually added HTTP headers (in PHP), but it didn’t work.

Leave a Reply