Skip to content
Advertisement

Apache RewriteMap prg using fopen(‘php://stdin’, ‘r’) not working over HTTPS

I’ve set up a RewriteMap using prg which calls a php script, like this:

 #!/usr/local/bin/php
<?php

/* DB query generates $map */

$stdout = fopen('php://stdout', 'w');
$stdin  = fopen('php://stdin', 'r');
            
stream_set_write_buffer($stdout, 0);
            
while(!feof($stdin)):
                
    $input  = fgets($stdin);
            
    fputs($stdout, (array_key_exists($input,$map) ? $map[$input] : 'NULL') . "n");
                
endwhile;
?>

And then .htaccess puts the output in an env variable MAPTO like this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
  RewriteRule ^ - [E=MAPTO:${mymap:%1}]
  RewriteCond %{ENV:MAPTO} !=""
  RewriteRule ^.*$ http://myproxiedcontent.com/%{ENV:MAPTO}/$0 [P,NC]
</IfModule>

It works correctly over HTTP, but over HTTPS no input is returned.

I’m using Apache 2.4, PHP 7.2 and have confirmed that OpenSSL is installed.

What could be going on here?

Advertisement

Answer

Okay, I believe I figured this out. I think the issue mainly has to do with the fact that I’m using WHM, which processes Apache configurations in an extremely convoluted manner.

I had to scour the httpd.conf file for my vhost configuration settings. At the bottom of those settings – where SSL was being configured – was a comment, indicating that settings related to this vhost should be added to:

/etc/apache2/conf.d/userdata/ssl/2_4/{USERNAME}/{DOMAIN}.{TLD}

I placed my RewriteMap setup here and now this is working.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement