#Http redirect
<VirtualHost *:80>
        ServerName brandhub-dev-1.brandhub360.com
        Redirect / https://brandhub-dev-1.brandhub360.com
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
   # ServerAdmin admin@brandhub-dev-1.brandhub360.com
    ServerName brandhub-dev-1.brandhub360.com
   # ServerAlias brandhub-dev-1.brandhub360.com

    # Set document root to be "basic/web"
    DocumentRoot "/var/www/html/web"

    <Directory "/var/www/html/web">
        # use mod_rewrite for pretty URL support
        RewriteEngine on

        # if $showScriptName is false in UrlManager, do not allow accessing URLs with script name
        RewriteRule ^index.php/ - [L,R=404]

        # If a directory or a file exists, use the request directly
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d

        # Otherwise forward the request to index.php
        RewriteRule . index.php

    </Directory>

    SSLProxyEngine on

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

# ProxyPass           /doceditor http://162.13.144.47/doceditor/
# ProxyPassReverse    /doceditor http://162.13.144.47/doceditor/
# ProxyPreserveHost  On

   # ServerSignature off

    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

    # 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

    LogFormat "%h %l %u %t \"%r\" %>s %b \"Custom Message: %{IFRAME_SOURCE}e\""custom_log
    CustomLog /var/log/apache2/access.log custom_log

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log custom_log

    ServerAlias brandhub-dev-1.brandhub360.com
    
    Include /etc/letsencrypt/options-ssl-apache.conf
   
    SSLCertificateFile /etc/letsencrypt/live/brandhub-dev-1.brandhub360.com-0001/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/brandhub-dev-1.brandhub360.com-0001/privkey.pem

</VirtualHost>
</IfModule>
