Forum Moderators: coopster & phranque

Message Too Old, No Replies

Can a CGI be run from htaccess

I want to log the visit and redirect

         

ThomasAJ

1:25 am on Sep 22, 2005 (gmt 0)

10+ Year Member



I have a CGI script that I use in all my pages (htm/html) that I want to run in a htaccess file. Can it be done?

The reason behind this is to track magazine ads. In magazine 'xyz' the ad I want to have says visit www.abc.com/xyz and then to have the htaccess in folder 'xyz' to log the visit and then redirect to my main page.

It begs the question "is this the best way" of tracking print ads. Seems to be very simple for the user.

Thanks
Tom

BananaFish

6:26 am on Sep 22, 2005 (gmt 0)

10+ Year Member



You could use mod_rewrite with eflag to write an environmetal variable that can be read by your cgi handler for the index page:

RewriteEngine On
RewriteRule ^/([a-z0-9]+) / [E=AFF:$1,L]

This would set the environmental variable "AFF" to the name of the sub-directory. But you may want to qualify it as an affiliate code in case you have other subdirectories such as "images". eg: precede the sub name with "aff-", www.abc/aff-xyz:

RewriteRule ^/aff\-([a-z0-9]+) / [E=AFF:$1,L]

KevinADC

6:55 am on Sep 22, 2005 (gmt 0)

10+ Year Member



you could also direct them to the script:

www.abc.com/cgi-bin/myscript.pl?add=xyz

your script parses the URI string, gets the add=xyz data and then redirects to the appropriate page.

could be done in PHP or ASP just as easily.

ThomasAJ

7:56 am on Sep 22, 2005 (gmt 0)

10+ Year Member



Thanks all I have enough info to go ahead.