Heal Your Church WebSite

Teaching, rebuking, correcting & training in righteous web design.

Not so Simple Redirect

From time to time, redirecting users is necessary. Take for example the a request/email I got from N.Z.Bear over at “The Truth Laid Bear:”

I finally got www.wmdi.org up and running. But here’s the deal:
… I’ve currently got all our stuff (weblog & forums) in a subdirectory of
TTLB: http://www.truthlaidbear.com/blogmd … So, I have a DNS forwarding service routing all requests for www.wmdi.org to, which is the IP address of www.truthlaidbear.com

In theory, I thought I would be able to use my .htaccess file to
implement mod re-write rules that would then allow me to transparently send
any requests to www.wmdi.org/blah to www.truthlaidbear.com/blogmd/blah …

Being that I’ve been remiss in helping NZ out with the WMDI, I figured I’d better reply him with some solutions. Here are four that you might also find useful if/when you run into a similar situation with your church web site. The first requires you add the following line to your .htaccess file in your website’s root directory – assuming you have a Linux/Apache configuration.

Redirect temp /blah http://www.truthlaidbear.com/blogmd/blah

Since NZ wants to redirect everything incoming to the /blah directory, he would need to modify the .httacess in his /public_html and/or the /www directory. The status argument [temp|permanent|seeother|gone] is only available in Apache 1.2 or later.

Keep in mind, redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration file. Also, Url-path must be an absolute path, not a relative path, even when used with .htaccess files or inside of <Directory> sections. Finally, don’t forget to chmod -644 that .htaccess file.

Then there are programatic approaches. First in PHP, then in Perl.

// —————- index.php ———————–
header(“Location: http://www.truthlaidbear.com/blogmd/blah”);
# —————- index.cgi ———————–
print “Location: $url\n”;

Being programatic approaches, this would mean you need to places these files in the “FROM” directory (/blah) and then chmod -755 the script files so you’ll know they execute. You also need to make sure your server is set up to look for index.cgi and/or index.php the same way it looks for index.html. This is default on most Linux/Apache configs, but if you mileage varys, then you may need to add the DirectoryIndex directive to your .htaccess file.

Of course, many of you who now have Linux/Apache set-ups do so through host providers that give you nifty little control programs such as CPANEL that let you set up redirects and such w/out having to SSH and PICO your way to fun and frustration – wimps.

And speaking of lightweight – there is always the HTML based solution:

<META HTTP-EQUIV=”Refresh” CONTENT=”0; URL=http://www.truthlaidbear.com/blogmd/blah”>

However, I’m not too fond of this one because it “blinks”, it sometimes fails, and it breaks the back button. That and its not as flexible as the above solutions, as you’ll see in blog a bit later how I’m dealing with someone linking the Redland site via a hate page. You know, the whole returning evil with good thing – more on that later.


  1. Hey Dean, thanks for the help. But I’m still struggling a bit, so I figured I’d respond here rather than in email so we can continue to share with the class.

    There’s one issue that I think we’re overlooking here that I suspect is significant: we don’t want to redirect all traffic that arrives at http://www.truthlaidbear.com/ to a new directory. We only want to redirect traffic that requested http://www.wmdi.org .

    The IP forwarding is sending both http://www.truthlaidbear.com and http://www.wmdi.org to the exact same spot right now — the web root of Truth Laid Bear. So what we need is a method for redirecting only those folks whose http request was for “wmdi.org” to a new directory — in particular, http://www.truthlaidbear.com/blogmd . (This is where I thought the Rewrite rules of .htaccess could be used, but they proved too complex for a simple bear to master — at least on my first attempt).

    And to be even pickier, I am ideally looking for a solution that makes this entirely transparent to a user. They should never see “truthlaidbear” in their browser; everything to them should appear to be http://www.wmdi.org/whatever . (I realize this will require some tweaking of the existing URLs on the site, but that’s ok).

    So, given that, will the solutions you suggest work, or am I correct in suspecting that something else may be required…?

    Thanks again!


  2. Actually, the best way to do this isn’t with mod_rewrite. While it’d be especially easy to do with mod_rewrite since both sites are on the same host (and I assume the same account), and just about as easy (but much more computationally expensive) if they had been on different hosts, because they’re on the same host the best thing to do is use a pointed domain.

    My host’s control panel lets me define pointed domains, where domain1.com points to “your account’s home directory”/domain1/. It all happens seamlessly. Go to http://www.devens.org/ for an example. That points to the same place as http://devens.keithdevens.com/ and http://www.keithdevens.com/devens/. Even though there’s nothing there, you can get the idea.

    If your host doesn’t have anything automatic to do this for you like my l33t host does, you should be able to ask them to do this for you.

  3. I’ve used Apache redirect a lot myself, and it works like a charm.

    Keith; the solution you are proposing is very ISP siesific, and if they make it that easy for you to set up virtual hosts (at no extra charge) something makes me think that they aren’t using “Real” virtual hosting (i.e. separate IPs for all virtual hosts). I use pair.com, and an explanation of their policy can be found here…


  4. From my understanding there is name-based virtual hosting and ip-based virtual hosting. In the past all accounts on my host were ip-based, but they’ve since switched mostly to name-based for new accounts, though you can still get a dedicated IP if you need one. This seems to be pretty common practice in the “virtual hosting community”. Here’s a post on my host’s message board explaining the issue[1]. My account does have a static IP, however. The “addon” virtual hosts like I suggested don’t get their own IP addresses. Keep in mind that for most people and for most purposes all of this doesn’t matter a bit.

    From what it says on the Pair site, it seems like while the first domain you have gets its own ip, any secondary virtual hosts don’t get their own IP’s either – though their wording isn’t totally clear on that and the only way to be sure would be to ask. I really doubt that they would, so the situation is the same on Pair.

    Also, this solution isn’t very ISP specific – any host using Apache should be able to do this for you easily. The only thing that may vary is what they change – my account comes with something like 10 of those free, while Pair charges for each one.

    [1] http://forums.hmdns.net/showthread.php?s=&threadid=5491

  5. You might want to consider editing the redirect so that wmdi.org points to the same place as http://www.wmdi.org; now it takes you to truthlaidbear.com, some of us *cough* me *cough* are to lazy to type in the www.