Operating System & Version
cPanel & WHM Version


Nov 11, 2019
Bellingham, WA
cPanel Access Level
Website Owner
I have a RewriteMap `prg` in the Pre VirtualHost Include (pre_virtualhost_global.conf) like this:

RewriteMap livemap "prg:/home/USER/applications/DOMAIN/public/rewriteMap.php"
The script listens on php://stdin for the domain, queries my database for a match, and then returns the rewrite path, like this:


/* DB query here, build $map... */

// Listen for input

$stdout = fopen('php://stdout', 'w');
$stdin  = fopen('php://stdin', 'r');
stream_set_write_buffer($stdout, 0);

    $input  = rtrim(fgets($stdin), "\n");
    fputs($stdout, (array_key_exists($input,$map) ? $map[$input] : 'NULL') . "\n");


Then, in my .htaccess file, I use this map to make my RewriteRules, like this:

<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]
This all works as expected unless I use HTTPS.

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.


Product Owner
Staff member
Nov 14, 2017
This seems as though it would be best suited in the domain's VirtualHost include Modify Apache Virtual Hosts with Include Files | cPanel & WHM Documentation

Also, I believe when using HTTP_HOST you specify that the request has to come from HTTP rather than HTTPS. In order for this to work when coming FROM https:// you'd need to use HTTPS_HOST in addition to HTTP_HOST in the rule using [OR] as defined in the mod_rewrite documentation

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap said:
You can also set special flags for CondPattern by appending [flags] as the third argument to the RewriteCond directive, where flags is a comma-separated list of any of the following flags:

  • 'nocase|NC' (no case)
    This makes the test case-insensitive - differences between 'A-Z' and 'a-z' are ignored, both in the expanded TestString and the CondPattern. This flag is effective only for comparisons between TestString and CondPattern. It has no effect on filesystem and subrequest checks.
  • 'ornext|OR' (or next condition)
    Use this to combine rule conditions with a local OR instead of the implicit AND. Typical example:
  • Code:
    RewriteCond "%{REMOTE_HOST}" "^host1" [OR]
    RewriteCond "%{REMOTE_HOST}" "^host2" [OR]
    RewriteCond "%{REMOTE_HOST}" "^host3"
    RewriteRule ...some special stuff for any of these hosts...
    Without this flag you would have to write the condition/rule pair three times.
  • 'novary|NV' (no vary)
    If a HTTP header is used in the condition, this flag prevents this header from being added to the Vary header of the response.
    Using this flag might break proper caching of the response if the representation of this response varies on the value of this header. So this flag should be only used if the meaning of the Vary header is well understood.