Forum Moderators: phranque
I use a simple mod_rewrite directive to hide the link "cgi-bin/script.pl" from the user and making it appear as a static link instead.
My perl script works perfectly fine when invoked as above, i.e. "localhost:/cgi-bin/script.pl".
This is the mod_rewrite config part of my httpd.conf:
RewriteEngine On
RewriteRule ^/script?$ "/cgi-bin/script.pl"
BUT, when when invoked as "localhost:/script", the actual source code of the script is returned to the client instead and shown as text. The script is not executed at all.
Does anyone have a clue to what is going on here? I'd be happy to supply more details if needed. Thanks in advance!
Jim
Welcome to WebmasterWorld!
The regex pattern in your rule is questionable, since the qustion mark makes the preceding "t" optional for a match. It does not represent a literal question mark in the URL-path, for which it would need to be written "script\?" instead of "script?". However, it may be a good thing, because RewriteRule will never see a literal question mark in the URL-path anyway; that character is stripped as the local URL-path is moved into the REQUEST_URI variable and the query string into the QUERY_STRING variable. These two parts of the request are handled separately by mod_rewrite.
However, I suspect that your problem is caused by the fact that your server has no way to know what content-handler to invoke, since the requested URL localhost:/script has no filetype associated with it. For this reason, you might want to try using the [T] flag on the RewriteRule, and defining the proper MIME-type for your script. This would make your rule look something like this, if I got the MIME-type right:
RewriteEngine on
RewriteRule ^/script$ /cgi-bin/script.pl [T=application/x-httpd-cgi,L]