2

Apache 2.4.27 on Oracle Linux 7 x64.

I can make proper calls to https://example.com/cgi-bin/helloworld.cgi.
The simple Perl script returns "Hello, world via cgi-bin!"

I can make proper calls to static content in https://example.com/helloworld.html
The simple HTML file returns "Hello, world via html!"

I can use RewriteRule as:

RewriteRule "^/test" "/helloworld.html"

I see "Hello, world via html!"

However, I cannot use RewriteRule as:

RewriteRule "^/test" "/cgi-bin/helloworld.cgi"

This results in a 400 Bad Request. How is it that I can call it directly though?

How do I get my RewriteRule to work when going to /cgi-bin? That seems to be my problem. I tried adding [L] and [L,PT] but no help.

1

I'm not sure what can be wrong in your configuration, how do you have ScriptAlias env set ?

I have tested with configuration below and everything seems to be fine on Apache 2.4.10 :

<VirtualHost 10.44.0.3:80>

    DocumentRoot "/vat/www/mysite"
    ServerName mysite.example.com
    ErrorLog "/var/log/apache2/mysite.example.com-error_log"
    CustomLog "/var/log/apache2/mysite.example.com-access_log" common

    ScriptAlias "/cgi-bin/" "/var/www/mysite/cgi-bin/"

    <Directory "/var/www/mysite">
          Require all granted
          Options Indexes FollowSymLinks MultiViews
          AllowOverride all
    </Directory>


    <Directory "/var/www/mysite/cgi-bin">
          Options +ExecCGI
          AddHandler cgi-script .cgi
    </Directory>


    RewriteEngine On
    RewriteRule "^/test" "/cgi-bin/test.cgi"

</VirtualHost>

opening http://mysite.exmaple.com/test opens up the cgi script

  • I think this may have to do with the fact that my RewriteRule was inside of my <Directory> and putting it outside, seems to help. The cgi-bin isnt my code, but it doesnt return 404/400... I get some app specific stuff. I THINK this fixes it, but I am emailing app people to test. Thank you for your help. I will update with a final answer soon – AaronG Oct 13 '17 at 0:22
  • 1
    @AaronG If your RewriteRule was inside a <Directory> container then your first test (RewriteRule "^/test" "/helloworld.html") also wouldn't have worked? But neither would this directive have resulted in a 400 response, as it simply would not have done anything - the RewriteRule pattern would not match inside a <Directory> container. So, there would seem to be something else going on here? – MrWhite Oct 13 '17 at 8:30
0

I add the same problem. When I used:

RewriteRule "^/test" "/cgi-bin/helloworld.cgi"

It didn't work. I had to use LogLevel alert rewrite:trace3 to check the logs. In my case, the rewritten path was being prefixed with document_root. So, instead of /cgi-bin/helloworld.cgi I was getting /var/www/html/cgi-bin/helloworld.cgi.

To solve the issue, I used two flags:

RewriteRule "^/test" "/cgi-bin/helloworld.cgi" [NC,PT]

This question is related to https://stackoverflow.com/questions/30065739/mod-rewrite-rewrite-url-to-point-to-cgi-script-but-keep-rewrite-hidden/30067581#30067581

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.