<VirtualHost *:80>
    DocumentRoot "/var/www/html/web"
    
    <Directory "/var/www/html/web">
        AllowOverride All
        Require all granted
    </Directory>

    # Proxy to CHILI servers
    ProxyPass          /cp-akw-054 https://cp-akw-054.chili-publish.online
    ProxyPassReverse   /cp-akw-054 https://cp-akw-054.chili-publish.online
    ProxyPass          /cp-dlq-564 https://cp-dlq-564.chili-publish.online
    ProxyPassReverse   /cp-dlq-564 https://cp-dlq-564.chili-publish.online

    SSLProxyEngine on


    ProxyRequests on
        <Proxy *>
            Order allow,deny
            Allow from all
        </Proxy>

    # Check if the Referer header contains "/cp-akw-054/"
    SetEnvIf Referer "^.*(/cp-akw-054/).*" IFRAME_SOURCE=cp-akw-054

    # Check if the Referer header contains "/cp-dlq-564/"
    SetEnvIf Referer "^.*(/cp-dlq-564/).*" IFRAME_SOURCE=cp-dlq-564

    ProxyPassInterpolateEnv On
    ProxyPass /js/chiliInternalWrapper.min.js https://${IFRAME_SOURCE}.chili-publish.online/js/chiliInternalWrapper.min.js interpolate
    ProxyPassReverse /js/chiliInternalWrapper.min.js https://${IFRAME_SOURCE}.chili-publish.online/js/chiliInternalWrapper.min.js interpolate

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>