mod rewrite clear home url for tomcat + apache

2019-06-14 04:58发布

问题:

I have a struts app running on Apache front end of Tomcat via mod-jk.

I am trying to use mod-rewrite to clean some of the action urls generate by struts.

Example: rewrite (works fine)

http://www.demo.com/context/user.do?action=aboutus to http://www.demo.com/context/aboutus using RewriteRule ^/msn/aboutus$ /msn/user.do?action=aboutus [PT,L].

Problem: I'd like to rewrite the http://www.demo.com/context/user.do?action=home to http://www.demo.com (homepage)

I tried this RewriteRule ^/$ /context/userdo?action=home [PT,L] which does not work.

FYI

All the css,js and links are on relative path.

DirectoryIndex is on index.html (Does it change mod-rewrite behaviour?)

Tomcat Version 5.5, Application deploy via exploding the WAR file in public_html/context/ folder (multiple deployment)

URLrewrite filter does not help to remove the context name according to this.

Logs

I tired to have a look at the log file (snapshots) which doesn't give any warning error messages.

(3) applying pattern '^/$' to uri '/context/jsps/images/abc.png'
(3) applying pattern '^/abc/aboutus$' to uri '/abc/jsps/images/abc.png'   
(3) applying pattern '^/abc/home$' to uri
'/abc/jsps/images/abc.png'

Anyone can give me some ideas what went wrong? and how can I solve that issue?

回答1:

I think in your case of rewriting ^/$ it is mod_jk that is taking precedence over mod_rewrite rules since using mod_jk you are forwarding everything eg: /* to Tomcat from Apache. I will suggest using URLRewriteFilter within your Tomcat app to achieve these URL rewrites properly.