I have a RewriteMap `prg` in the Pre VirtualHost Include (pre_virtualhost_global.conf) like this:
The script listens on php://stdin for the domain, queries my database for a match, and then returns the rewrite path, like this:
Then, in my .htaccess file, I use this map to make my RewriteRules, like this:
This all works as expected unless I use HTTPS.
For example, if I visit
However, if I use
I can't figure out why this is working over HTTP and not HTTPS.
The primary domain and the alias are on the same SSL cert. I used LogLevel rewrite:trace8 to tail the rewrites and I can see it's applying the same rules over HTTPS, but not returning a MAPTO value whereas HTTP will.
Code:
RewriteMap livemap "prg:/home/USER/applications/DOMAIN/public/rewriteMap.php"
PHP:
#!/usr/local/bin/php
<?php
/* DB query here, build $map... */
// Listen for input
$stdout = fopen('php://stdout', 'w');
$stdin = fopen('php://stdin', 'r');
stream_set_write_buffer($stdout, 0);
while(!feof($stdin)):
$input = rtrim(fgets($stdin), "\n");
fputs($stdout, (array_key_exists($input,$map) ? $map[$input] : 'NULL') . "\n");
endwhile;
exit;
?>
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ - [E=MAPTO:${livemap:%1}]
RewriteCond %{ENV:MAPTO} !=""
RewriteRule ^.*$ https://mywebsite.com/%{ENV:MAPTO}/$0 [P,NC]
</IfModule>
For example, if I visit
http://myaliaswebsite.com
, my RewriteMap will return the DB result and .htaccess will set the MAPTO env variable with its value, allowing me to proxy the appropriate content on mywebsite.com.However, if I use
https://myaliaswebsite.com
, the RewriteMap doesn't return a result — it doesn't apepar to receive any input at all — and no value is stored in MAPTO, thus failing the RewriteCond.I can't figure out why this is working over HTTP and not HTTPS.
The primary domain and the alias are on the same SSL cert. I used LogLevel rewrite:trace8 to tail the rewrites and I can see it's applying the same rules over HTTPS, but not returning a MAPTO value whereas HTTP will.