0

I am having difficulty defining a correct RewriteRule to forward requests to an application running in tomcat. I have apache with mod_rewrite enabled as well as tomcat setup with an application mounted with mod_jk. Without a virtual host, I can browse to the following url without issue. (context being the application running in tomcat)

http://www.domain.com/context

How do I configure the RewriteRule to pass requests from domain.com to the application running in tomcat.

http://www.domain.com --> http://www.domain.com/context

Here is what my current virtual host file looks like

<VirtualHost *:80>
        ServerName www.domain.com

        <Directory />
                Options FollowSymLinks
                AllowOverride None
                RewriteEngine On
                RewriteRule \/$ /context [L]
        </Directory>

        <Directory /var/www/html/context/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny                                         
                allow from all                                           
        </Directory>

</VirtualHost>

This will pass the request from domain.com to a directory named context in /var/www/html. How do I override the default apache setup to pass the request to the application running in tomcat?

Thanks in advance for your help.

Mike Croteau
  • 101
  • 4
  • 1
    Thanks. My RewriteRule is working in a sense, its passing the request to a directory named after my tomcat application in apache web directory (/var/www/html/context). I need to override this so that the request get passed to tomcat, not to the context directory in apache. – Mike Croteau Jan 27 '15 at 23:01

2 Answers2

0

Something like this, where localhost:8080 is where your tomcat server is running.

RewriteRule ^/(.*)$ http://localhost:8080/context/$1 [L,P]
mefju
  • 153
  • 5
Julia Leder
  • 121
  • 5
0

I edited my virtual host file. I added the JkMount inside the virtual host file instead of 000-default.conf and was able to get apache to pass the request to the tomcat application instead of the folder in apaches web directory. I also now have 2 virtual host files, one for the main domain and the other for the domain without www. prefix. Here is what they look like :

www_domain.conf

<VirtualHost *:80>

        ServerName www.domain.com

        JkMount /context* ajp13_worker

        <Directory />
                Options FollowSymLinks
                AllowOverride None
                RewriteEngine On
                RewriteRule \/$ /context [L]
        </Directory>

</VirtualHost>

domain.conf

<VirtualHost *:80>
        ServerName domain.com

        RewriteEngine On
        RewriteRule \/$ http://www.domain.com [L] 
</VirtualHost>
Mike Croteau
  • 101
  • 4