Apache reverse proxy fails without trailing slash

Apache2reverse-proxy

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

</VirtualHost>

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:

RewriteRule

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.

Best Answer

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/