i am trying to rewrite the url in apache which internally redirect the requests to apache tomacat
Here is my httpd.conf code
<IfModule mod_rewrite.c>
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/myapp/my.html
ProxyPassReverse / http://localhost:8080/myapp/my.html
RewriteEngine on
RewriteRule ^/(.*)/$ http://localhost:8080/myapp/my.html?product=$1 [QSA]
</IfModule>
so basically what i am trying to do is if i enter localhost/myapp then it should redirect me to localhost:8080/myapp/my.html
Next is if i enter the url localhost/myapp/8 it should redirect internally to localhost:8080/myapp/my.html?product=8.
Now the problem is ProxyPass is working absolutely fine. But the rewrite rule is showing 404 error. If i remove the ProxyPass code then the same rewrite rule works but it shows the modified url in the browser. So i want to know where should i place RewriteRule to make it work with ProxyPass and y the rewrite rule is showing the modified urls?
You need to add the
[P]
flag to theRewriteRule
. This causes theRewriteRule
to 'proxy' the same way yourProxyPass
directive does. At the moment your rule doesn't make any sense. Alternatively you could do something like:Which should cause the URL to be rewritten and then passed through (this happens because of the
PT
flag) to any remaining modules that need to process the URI path, in this case the proxy module.FYI the terminology is wrong, when you say
if i enter localhost/myapp then it should redirect me to localhost:8080/myapp/my.html
you really meanif i enter localhost/myapp then it should proxy to localhost:8080/myapp/my.html
. A redirect is an external response which cases the browser to request a new URL and the text in the browsers address bar will change.Mind you, with your current configuration, requesting
localhost/
will proxy tolocalhost:8080/myapp/my.html
. So if you can specify which is correct it would help.