faqts : Computers : Internet : Web Servers : Apache : Installation and Setup

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 9 people (67%) answered Yes
Recently 6 of 9 people (67%) answered Yes


How can I alias any file accessed under a particular resource to a single CGI script?

Nov 16th, 2001 00:04
Anthony Boyd, Paul Raulerson,

In Apache's httpd.conf file, you need to look for the redirect stuff.  
You need to add a line similar to the following:
RedirectMatch ^/particularesource/.*$ /cgi-bin/single.cgi
That takes anything in "particularesource" and instead sends the 
browser to single.cgi.  Substitute your own directory names and CGI 
names as needed.  Here's what the funny characters mean:
^ = must begin here, nothing before this
$ = must end here, nothing after this
. = any single character
* = multiple characters
.* = multiples of any character
Cool side-note.  You can tell the CGI what page the person asked for.  
I haven't tested this code, but try this:
RedirectMatch ^/particularesource/(.*)$ /cgi-bin/single.cgi?url=$1
So if you requested "/particularesource/foo.html" then what's requested 
by the browser is actually "/cgi-bin/single.cgi?url=foo.html" -- and 
from that, you can use Perl to parse the query string and log who asked 
for what, or return different HTML depending on the request, etc.