I have an apache conf that uses ProxyPass and ProxyPassReverse like this:

ProxyPass /api/v1/ http://navigator:5000/
ProxyPassReverse /api/v1/ http://navigator:5000/

Response headers from the navigator service that use the Location field correctly get rewritten so:




But ProxyPassReverse doesn't support rewriting the Link field of the response header, which I use for pagination (much like e.g. https://developer.github.com/v3/#pagination).

So when navigator responds with a header that has the Link set to:

<http://navigator:5000/foo/bar?fromid=5cebb4724662a700099a9e56>; rel="next"

It won't be rewritten into the expected:

<http://localhost/api/v1/foo/bar?fromid=5cebb4724662a700099a9e56>; rel="next"

I have not found any other apache module that would do the job, granted I'm no expert on server configuration. I know there are ways to rewrite html/xml links in the response body, but since this is in the header and doesn't really look like html-links, that solution doesn't seem to apply.

How would I get those links rewritten?


Based on the suggested answer, I have the following config that almost does what I want:

Header edit Link "http://navigator:5000/" "/api/v1/"

The configuration is used for several hosts (as an example staging.example.com, www.example.com and localhost:5000) so I can't use a hard coded string.

I could probably leave the link without host specified as a relative link, but I would be most happy if the edit could insert the host used in the request.

I've attempted to have the rewrite part be "%{HTTP_HOST}/api/v1/", "%{HTTP_HOST}e/api/v1/", "{%HTTP_HOST}s/api/v1/" and "$HTTP_HOST/api/v1/" but none of them give the wanted result.


You can use "Header" directive and edit particular header.

And the directive will look like:

Header edit Link expr="/foo/bar" /api/v1/foo/bar

You you need to replace also localhost you can add one more directive

Header edit Link expr="localhost" your_host_name

To use hostname you can use variable HTTP_HOST

Header edit Link "http://navigator:5000/" "${HTTP_HOST}/rest_api/v1/"
  • I started digging based on your example. For some reason it doesn't do anything if I include always as you wrote. And I based on my experimentation I've gotten to: Header edit Link "http://navigator:5000/" "%{HOST}e/rest_api/v1/", but HOST doesn't exist, that is don't know how to insert the host and port of the request in rewriting the response header – Martin Zackrisson May 29 at 11:50
  • @MartinZackrisson, as your host (in returned header) is always localhost you can replace it adding one more Header directive. Will edit my answer – Romeo Ninov May 29 at 12:00
  • The conf is deployed for several hosts like staging.example.com and www.example.com so I would need to get the actual host used in the request, but otherwise Header edit Link "navigator:5000" my_host_name would have worked to rewrite that part. – Martin Zackrisson May 29 at 12:07
  • @MartinZackrisson, try to use HTTP_HOST as variable – Romeo Ninov May 29 at 12:11
  • %{HTTP_HOST} gives syntax error. I think that mod_headers only support either %{HTTP_HOST}s or %{HTTP_HOST}e but both of those report as null, so I'm probably missing something basic here. – Martin Zackrisson May 29 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.