How to reverse proxy with or without trailing slash
I have an Apache web server that needs to reverse proxy a site. So example.com/test/
or example.com/test
pull from the same other webserver. I have setup a reverse proxy for the one without the trailing slash like this:
ProxyPass /test http://othersite.com/test
ProxyPassReverse /test http://othersite.com/test
But it doesn't work with a trailing slash.
Any Ideas? I have tried redirecting from /test/
to /test
with no luck.
Thanks.
Solution 1:
Have you tried to rewrite the url?
RewriteEngine on
RewriteRule ^/test$ /test/ [R]
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /test/ http://othersite.com/test/
ProxyPassReverse /test/ http://othersite.com/test/
Solution 2:
What do you mean it doesn't work with a trailing slash? Does it redirect to the wrong place? Does it give a 404 error? This is what I used to set up a reverse proxy and hide the source from the rest of the world.
ProxyRequests off
<Location /guides>
ProxyPass http://blog.domain.com
ProxyPassReverse http://blog.domain.com
ProxyPassReverse /
ProxyHTMLEnable On
ProxyHTMLURLMap / /guides
ProxyHTMLURLMap http://blogs.domain.com /guides
RequestHeader unset Accept-Encoding
RequestHeader set MySpecialHeader secretkey
#LogLevel proxy:debug
</Location>
You can use this to test your proxy:
$ curl -I http://localhost:81/guides/top5
HTTP/1.1 301 Moved Permanently
Location: http://localhost:81/guides/top5/