1

I wrote a MVC Servlet + JSP web application and deployed in Apache+Tomcat. I don't call JSP directly, but I use them as view and I call them from the Servlets.

To make it visible in a virtual host, I mapped it using JkMount:

JkMount /MyApplication/* ajp13_worker

However now to access MyApplication I've to write URLs as

http://www.example.com/MyApplication/MyServlet

I would like to be able to call MyServlet from the root of my virtualhost such as in:

http://www.example.com/MyServlet

How do I do this?

stivlo
  • 749
  • 3
  • 10
  • 24

1 Answers1

0

How about:

RewriteEngine On
RewriteRule ^(/MyServlet.*) /MyApplication$1 [passthrough]

The passthrough will allow mod_jk to take the request after being processed by mod_rewrite

dialt0ne
  • 3,065
  • 20
  • 27
  • thank you, this works, I added a RewriteRule to get to the first servlet: "RewriteRule ^/$ /index [R]", however, when in a servlet I call "response.sendRedirect("my-servlet");", it adds the /MyApplication prefix again. Maybe I should call "response.sendRedirect("/my-servlet"); – stivlo Feb 01 '11 at 10:00
  • I don't know about response.sendRedirect but I suspect it returns a relative URI. Tomcat doesn't know about the RewriteRule. Another option is to deploy your application as ROOT.war with "JkMount /* ajp13_worker" in the apache config. Tomcat will still redirect requests to other applications, but will recognize your servlets in the "/" path. – dialt0ne Feb 01 '11 at 13:43