Mod rewrite for CGI file to PHP file

Hi,

Was wondering if anyone can help me out, im trying to redirect a CGI request to a PHP one using a rewrite rule

This is what im trying to use


RewriteRule ^cgi-bin/cart.pl?IT=([A-Za-z0-9-]+) /script/redirect.php?code=$1

So the URL I am redirecting is domain.com/cgi-bin/cart.pl?IT=TP3229 (can be any code A-Z 0-9) to domain.com/script/redirect.php?code=TP3229

The code I am using doesn’t seem to work, am I doing something wrong?

Any help greatly appreciated,

Michael

The rewrite rule can only match against the request URI (cgi-bin/cart.pl), not the query string

You need to use a rewrite condition for that

Try this

RewriteCond %{QUERY_STRING} IT=([A-Za-z0-9-]+)
RewriteRule ^cgi-bin/cart.pl /script/redirect.php?code=%1

Michael,

The cgi-bin is typically a directory OUTSIDE the webspace and it’s an internal directive (which uses mod_alias) to get to. In other words, I’ve failed completely to affect cgi-bin code because of this and can only recommend changing your .pl scripts to redirect for you if that’s the case on your server (assuming that you cannot move the cgi-bin to your WEBSPACE).

Regards,

DK

Thanks guys! So the only solution is to edit the .pl script to carry out the redirect since it can’t be done in htaccess?

Bytecon,

IMHO, IF your cgi-bin is NOT in your website’s directory (in your webspace), then I’m afraid that’s the case.

Regards,

DK

Thanks for the help David!