I'm currently trying to set up a Reverse Proxy with Apache. I went with the following config:

<VirtualHost *:80>
  ServerName my-server

  SSLProxyEngine on
  SSLProxyVerify none 
  SSLProxyCheckPeerCN off
  SSLProxyCheckPeerName off
  SSLProxyCheckPeerExpire off

  ProxyPreserveHost on
  ProxyRequests off
  ProxyPass "/c/"  "https://other.server.com/"
  ProxyPassReverse "/c/"  "https://other.server.com/"

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


The problem I've encountered is that when I navigate to localhost:8080/c/slug/ it works as expected, yet when I navigate to localhost:8080/c/slug it redirects me to localhost:8080/slug instead of getting the content from the proxied server.

When inspecting the call headers I found a 301: Moved permanently.

HTTP headers

On the other hand, while inspecting the call that works, it all appears fine:

enter image description here

I've tried the following ideas, but none have happened to work:


Adding a rewrite rule:

  RewriteEngine on
  RewriteRule "slug$" "slug/" [L,R=301]

Explicitly typing the URL

Explicitly typing the URL I'm trying to access without the forward slash:

  ProxyPass "/c/slug"  "https://other.server.com/"
  ProxyPassReverse "/c/slug"  "https://other.server.com/"

I have also tried turning on and off the ProxyRequests, but also didn't work.

Any help is appreciated.

  • ProxyPassReverse should be taking care of correctly rewriting HTTP redirect headers but will only rewrite a few specific ones (see httpd.apache.org/docs/2.4/mod/mod_proxy.html) so start by inspecting the headers you get when you access the URI without a trailing / - also including or omitting the trailing / in the ProxyPass directive should be the same on both the local path prefix and the remote URI – HBruijn Nov 21 '18 at 22:16
  • @HBruijn I inspected the headers, although I don't really understand the results. I added them to the question. Does the 301 tell you anything that might be going on? – Javier García Manzano Nov 22 '18 at 13:09
  • This is most probably a configuration issue on other.server.com, not your reverse proxy. Fetch https://other.server.com/slug and see what happens. – Gerald Schneider Nov 22 '18 at 13:14
  • The "moved permanently - from disk cache" shows at least one of your problems. A Permanent redirect (the result of your testing with [L,R=301] flags?) is exactly that: permanent and will be cached by a web browser. If you made a mistake and don't clear your caches (or don't do each new test in a new anonymous window) then any changes you make in the server configuration won't become apparent as your webbrowser will change the request for you even before it gets sent to a server. – HBruijn Nov 22 '18 at 13:22
  • @GeraldSchneider @HBruijn so I just went and checked the other.server.com and there is something fishy going on. It does deliver the content on both urls, both with and without the forward slash, but when I GET the content without the forward slash it does return a 301. Do you think this might have to do with my proxy returning that 301 and not displaying content? I have tested this on an anonymous window. – Javier García Manzano Nov 22 '18 at 13:26

I had a similar problem, but in my case I was redirecting a VirtualHost from HTTP to a VirtualHost with HTTPS, and in my Redirect directive it was missing the final /.

For example: Redirect / https://localhost

And I solved with: Redirect / https://localhost/

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.