Forum Moderators: phranque

Message Too Old, No Replies

Windows, cgi-bin, perl, mod_rewrite problem

Scripts mangled through mod_rewrite do not execute, instead shown as text

         

jim_nilsson

7:03 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



This is a problem experienced on A Windows machine running Apache 2. (Have tested the same thing on a Linux machine, and on it, everything works fine. Not completely similar config-files though.)

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

jdMorgan

2:51 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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]

[Jim]

jim_nilsson

7:48 am on Aug 12, 2005 (gmt 0)

10+ Year Member



Thank you!

This solved the problem perfectly.

As it turns out, Apache 1.x did not need the mime-type brackets, but Apache 2 did. Thanks also for the clarification about the question mark in the regexp!

Jim