Search code examples
mod-rewriteapache2mod-proxycrafter-cms

Apache 2.4 proxy add request parameter to all requets


I am using Crafter CMS with multi-tenancy. I am trying to setup Apache2.4 on RHEL7 to be a reverse proxy. http://site.example.com -> ajp://localhost:9009/?crafterSite=site

Here is my Apache2 virtual host configuration. I have ensured that mod_proxy and mod_rewrite are loaded. I can reach Crafter Delivery through the proxy but the rewrite isnt working as Crafter doesnt know what site I am trying to load. Does anyone have any suggestions on how to get this working.

<VirtualHost *:80>
    ServerName site.example.com
    LogLevel alert rewrite:trace3
    RewriteEngine  On
    RewriteRule ^$ /?crafterSite=site [QSA,L]

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

    ProxyRequests           Off
    ProxyPreserveHost       On
    ProxyPass               /       ajp://localhost:9009/
    ProxyPassReverse        /       ajp://localhost:9009/
</VirtualHost>

Solution

  • Try changing the rewrite rule to be:

    RewriteRule (.*) $1?crafterSite=site [QSA,PT]

    Where site is your site ID.

    The differences are:

    • It rewrites anything coming in regardless of URL and preserves it (see the (.*) and $1)
    • It's a passthrough PT (not a redirect). This means it augments the request with the param and lets it straight through to Crafter Engine.