1

I've a website that need Tomcat (opened on 8080 port) on my server. So I wrote this .conf on apache2 available site:

 DocumentRoot /var/www/html

 <Proxy *>
    Order deny,allow
    Allow from all
 </Proxy>
 ProxyPreserveHost On
 ProxyPass / http://example.com:8080/deploydir/
 ProxyPassReverse / http://example.com:8080/deploydir/

 RewriteEngine on
 RewriteRule ^deploydir/(.*)$ /$1 [R=301,NC,L]

But RewriteRule doesn't work, why? I want to redirect a directory (with files and subdirectories) into another (in this case root directory), how can I do this?

3
  • Rewriting URLs while simultaneously proxying them to Tomcat (or any other servlet container) is a recipe for disaster. All kinds of bad things happen. Instead, proxy /foo to /foo and use redirects to send users from / to /foo. Your life will be much simpler if you do this instead of constantly fighting all the problems you'll experience if you try rewriting the URL. Remember you can always use the ROOT context if you want to proxy / -> /. Jul 14, 2016 at 13:48
  • Ok, thanks. But what if I have more than one service to redirect with a proxy on Apache? Root dir is only one...
    – NickF_93
    Jul 15, 2016 at 8:09
  • If you have more than one application to proxy, then you should use two different URL spaces (e.g. /app1 and /app2). If users have a choice, give them a choice. If they don't, always redirect them to the one you see as the "primary" web application. Jul 15, 2016 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.