buzzword compliance

A Three-way homepage switch in PHP

Since I've been consolidating hosting of some of my domains, I ran into a little bit of a problem; I had three domain names pointed at the same host, and I wanted each of the domains to have its own home page. So, 10 minutes of PHP coding later, my problem was solved.

I inserted a simple redirector based on the $HTTP_HOST and $REQUEST_URI server variables in PHP, which capture the URL that the user has requested. The rest is just sending standard HTTP redirect headers, so that the user will be forwarded to the page they've come looking for.

I reused a code-snip from an earlier project that creates a string variable that stores the fully-expressed URL of the site, just in case I decide to add some other options later.

The switch uses the stringsearch function “strstr” to find the text for which domain the incoming request is pointed at, then sends back a header to redirect users to the corresponding directory for the homepage of that site. Extending this, I can now on a single host maintain as many domains as the provider will let me point at the site, and as storage will allow.

To build a home page that redirects based on the incoming URL, (if your site supports PHP), use this code and substitute your own domain names. If you've got more than three, just repeat the “if” statements as many times as you need to. (It's not pretty, but it works.)

<html>
<head>
<?php
$url = sprintf("%s%s%s"," http://&quot;,$HTTP_HOST,,br>
$REQUEST_URI );
if (strstr($url, "INSERT DOMAIN NAME #1 HERE")) {
?>
<title>Forwarding to INSERT DOMAIN NAME #1 HERE</title>
<meta http-equiv="Refresh" content="1; URL=http://DOMAINNAME#1.com/DIRECTORYOFHOMEPAGE/">
<?
}
if (strstr($url, "INSERT 2ND DOMAIN NAME HERE"))
{
?> <title>Forwarding to 2ND DOMAIN NAME Home</title> <meta http-equiv="Refresh" content="1; URL=http://www.2NDDOMAINNAME.com/DIRECTORYOF2NDHOMEPAGE/">
<?
}
else { ?>
<title>Forwarding to 3RD DOMAIN homepage</title>
<meta http-equiv="Refresh" content="1; URL=http://www.3RDDOMAIN.com/index2.html">
<?}
</head>

Standard
General Chaos

Rainy days and Tuesdays

It's a cold wet blanket of a day, grey and rainy and just warm enough that the rain isn't instantly turning to sheets of ice to send the trucks from the bottling plant at the bottom of the hill sliding into a massive heap of twisted metal. Yeah, that's the kind of day it is–one that makes you wish it were that one degree colder, so everything would crust over, and then there'd be a better excuse for not going out into the wet, cold maw of the day.

I need more coffee.

My daughter woke up at 2 AM this morning, tossing in her little toddler bed, having thrown off her covers at some point and waking to the chill. I was so tired I just picked her up and brought her back to our bedroom, hoping that she would settle down again between her mom and I. Instead, she performed nocturnal acrobatics, nearly forcing me onto the floor. I finally gave up on sleep for the short term at 4 AM, and hauled her back to her room, where I rocked her to sleep in the rocking chair we put there for just such an occasion.

Thus sleep deprived, I sent my wife out into the cold maw of the morning to take our boys to school while I got another 15 glorious minutes of undisturbed slumber. This, of course, meant that I started fielding the first phone calls of the day in my pajamas; this is the benefit and the drawback of working from home.

Now, I've got to face the day. My head is still ringing with the leftover facts and quotes and prose from the case study I rewrote over the weekend; let's just say if I were to never see another greeting card in this life, it would be fine with me.

God, I'm crotchety today. Maybe I should dig out the espresso maker that's been gathering dust in the kitchen cabinet and steam myself a quadruple shot. Maybe put some Maker's Mark in it to take the edge off the day. Er…I guess it's too early in the day to start mixing drugs like that.

Standard