Using Apache httpd to redirect context path?
Short answer: no, not really. Typically, your backend application needs to have an option for configuring its own root URL so that it can generate appropriate links. If your backend application is hosted in something like Tomcat, then just install it such that it's available at the same relative path (so that, for example, you're proxying from example.com/public/
to localhost:1006/public/
).
Related videos on Youtube
![Robert Seal](https://i.stack.imgur.com/veyfL.jpg?s=256&g=1)
Comments
-
Robert Seal almost 2 years
I'd like to proxy
http://localhost:1006/
ashttp://example.com/public/
to the outside world. Here is my configuration:RewriteEngine On # Append a slash if necessary RewriteRule ^/public$ public/ [R,L] # Request headers: Replace http://localhost:1006/ with http://example.com/public/ ProxyPass /public/ http://localhost:1006/ # Response headers: Replace http://example.com/ with http://example.com/public/ ProxyPassReverse /public/ http://example.com/ ProxyPassReverseCookiePath / /public/ <Location /public> Require all granted </Location>
This works well for rewriting headers, but the server still thinks its context path is
/
instead of/public/
so when it constructs URLs for embedding into JSON they are incorrect. Httpd only rewrites headers, not the JSON, so it does nothing about this.I don't want httpd to rewrite the JSON (I read the process is unreliable). I noticed that the
Host
header sent by httpd to the server contains the external hostname, which enables the server to correct that part of the URL. Is there some other header I could set which would instruct the server to use a different context-path?Meaning, is there anything I can do on httpd which would alter the server's context-path without altering the server's configuration/code directly?
-
Robert Seal almost 11 yearsI suspected as much, but I'll ask just in case: Are you absolutely sure there is no way? Or are you saying it's not worth the effort? :)
-
user2751502 almost 11 yearsIt really depends on your application. If it's something common and you can tell us what it is, maybe there are application-specific fixes. Otherwise, short of some sort content filter, I think you're out of luck. For HTML pages, mod_proxy_html can help with this sort of thing, but it wouldn't really be appropriate for
JSON
. -
Robert Seal almost 11 yearsI can modify the application (running Jetty HTTP server) to take a context-path. I was just hoping there was a way to do this without altering the application code but that's alright. Thanks!