简体   繁体   中英

Apache server RewriteRule to Tomcat war - Remove application name from url

I'm having problems with RewriteRule. My tomcat application is Xyz and it is placed in its folder on localhost. Server name is www.mydomain.com. Application can be reached with www.mydomain.com/Xyz, but I would like to reach it with www.mydomain.com. Is it possible to achieve this with RewriteRule?

I use JkMount within the Apache configuration file:

JkMount /Xyz worker1
JkMount /Xyz/* worker1

where worker1 is member of worker defined as:

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.lbfactor=1

I tried to add to the Apache configuration file RewriteRule just before JkMount:

ServerName www.mydomain.com
RewriteEngine on
RewriteRule ^/(.+)$ /Xyz/$1 [L,PT]

but with no success. Application can be easily reached with www.mydomain.com/Xyz, but www.mydomain.com doesn't work at all. it just produces error message...

Any suggestions?

If you are happy not to use URL rewrite you can achieve similar by defining ROOT context.

Detailed Tomcat Context documentation here

[ Note: didn't try this, will do later ] I'd suggest you move your move application to a directory outside of your /webapps, eg. /myapps/xyz/; and then add a file to define your application context (for Tomcat 7)

$CATALINA_HOME$/conf/Catalina/localhost/ROOT.xml 

for previous Tomcat version probably something like:

$CATALINA_HOME$/conf/ROOT.xml 

In ROOT.xml define where your application root (docBase) is and l eave path element empty

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <Context deployOnStartup="true" docBase="/myapps/xyz/" path="" reloadable="false">
    <Manager pathname=""/>
</Context>

Similar posts are here

Srecno

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM