Apache rewrite rules not working after adding proxy pass

I am trying to rewrite url in apache which internally redirects 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 login to localhost / myapp then it should redirect me to localhost: 8080 / myapp / my.html

Next, if I enter the url localhost / myapp / 8, it should redirect internally to localhost: 8080 / myapp / my.html? product = 8.

Now the problem in ProxyPass is working absolutely fine. But the rewrite rule shows a 404 error. If I remove the ProxyPass code, the same rewrite rule will be executed, but the changed URL will be displayed in the browser. So I want to know where should I place the RewriteRule in order to get it to work with ProxyPass and the changed urls are displayed in the rewrite rule?

+3


source to share


1 answer


You need to add a flag [P]

to RewriteRule

. This causes the RewriteRule

"proxy" to be similar to your directive ProxyPass

. At this point, your rule doesn't make any sense. Alternatively, you can do something like:

RewriteRule ^/(.*)/$ /myapp/my.html?product=$1 [QSA,PT]

      

This should cause the URL to be rewritten and then passed (this happens because of the flag PT

) to any other modules that need to handle the URI path, in this case the proxy module.



FYI terminology is wrong, when you say if i enter localhost/myapp then it should redirect me to localhost:8080/myapp/my.html

you really mean it if i enter localhost/myapp then it should proxy to localhost:8080/myapp/my.html

. A redirect is an external response in which the browser asks for a new url and the text in the browser's address bar changes.

Remember, with your current configuration, the request localhost/

will be proxy to localhost:8080/myapp/my.html

. So if you can point out what is correct it will help.

0


source







All Articles