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 22.214.171.124, 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.
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.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:
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.