I have a seemingly easy task, but somehow I just can't get it to work:

Some interesting lines from my httpd.conf:

DocumentRoot "D:/opt/apache/htdocs"
ScriptAlias /cgi-bin/ "D:/opt/apache/cgi-bin/"
<Directory "D:/opt/apache/htdocs">
   Options Indexes FollowSymLinks ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
<Directory "D:/opt/apache/cgi-bin/">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all

(I know it's dumb but it's only a testing machine :D.)

Now, I have d:\opt\apache\cgi-bin\expired.pl and I expect GET /licensecheck.php?code=123456. And I wish to fake client into thinking it speaks with /licensecheck.php, but actually return data by \expired.pl.

What I tried was setting following at the end of http.conf:

RewriteEngine on
RewriteRule ^/licensecheck.php$ /cgi-bin/expired.pl [T=application/x-httpd-cgi,L]

...but it keeps 404-ing me, looking for cgi-bin directory (not cgi-bin\expired.pl) in my DocumentRoot!

[error] [client] script not found or unable to stat: D:/opt/apache/htdocs/cgi-bin
  • /cgi-bin/expired.pl and all other scripts in /cgi-bin/ work as expected,

  • Only way I could make it work was actually putting the \expired.pl to DocumentRoot, but I don't want this, I want my cgi-bin neatly separated :)

  • 1. Do you have a Directory directive for "D:/opt/apache/cgi-bin/" with permission set correctly? 2. Where did you put the RewriteEngine on et alli? – Chris S Jul 12 '11 at 17:49
  • 2
    Try [PT] flag: httpd.apache.org/docs/current/rewrite/flags.html#flag_pt – LazyOne Jul 12 '11 at 20:17
  • @ChrisS: Updated according to your questions – Alois Mahdal Jul 12 '11 at 20:20
  • @LazyOne: Thanks, that actually works! Seems that I misunderstood mod_rewrite--i thought that was taken as URI. Thanks again all yoou guys! – Alois Mahdal Jul 12 '11 at 20:26
  • @AloisMahdal Please answer to your question, and check it as "Ok". – Olivier Pons Nov 14 '11 at 21:14

The problem was just a misunderstanding; I thought that the subject for rewrite is implicitly taken as URI.

Adding [PT] changed the behavior, which solved my problem:

RewriteRule ^/licensecheck.php$ /cgi-bin/pct-expired.pl [T=application/x-httpd-cgi,L,PT]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.