Skip to content

Instantly share code, notes, and snippets.

@chirauki
Created January 17, 2017 13:52
Show Gist options
  • Save chirauki/4d20b27c171095e149317ad61277cb1b to your computer and use it in GitHub Desktop.
Save chirauki/4d20b27c171095e149317ad61277cb1b to your computer and use it in GitHub Desktop.
Modify JSON links in response

Modify JSON links in response

This allows, for example, changing the host or path in a HTTP link on a JSON response body.

Enable mod_filter and mod_substitute. Adjust vHost according to Apache version.

Apache 2.2

<VirtualHost *:443>
    ServerName wf.bcn.abiquo.com
...

    FilterDeclare rename_host
    FilterProvider rename_host SUBSTITUTE resp=Content-Type $json

    <Directory "/var/www/html/ui">
...

    <Location /api>
        ProxyPass ajp://localhost:8010/api
        ProxyPassReverse ajp://localhost:8010/api
        FilterChain rename_host
        Substitute s/wf.bcn.abiquo.com/test.example.org/i
    </Location>
...

Apache 2.4

...

FilterDeclare rename_cms
FilterProvider rename_cms SUBSTITUTE "%{CONTENT_TYPE} =~ /json/"

...

<Location "/cmsSwisscom">
   ProxyPass https://stmz000238.tmzintra.ch/Appclusive/api
   Header add "Access-Control-Allow-Origin" "*"
   FilterChain rename_cms
   Substitute "s,https://stmz000238\.tmzintra\.ch/Appclusive/api/,http://localhost/cmsSwisscom/,i"
</Location>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment