Related to some of my earlier questions.

I now have a setup I quite like;

Apache httpd listening on port 80 accepting http and https connections. Several Tomcat instances running on several AJP ports.

Mod_Jk is sending different url requests to different tomcat instances;

www.mydomain.com/demo -> tomcat:8101
www.mydomain.com/test -> tomcat:8102
www.mydomain.com/     -> tomcat:8100

This is achieved with the following config in httpd.conf (or included sub files);

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

NameVirtualHost *:80

<VirtualHost *:80>
    JkMount /demo* demoTomcat (workers.properties not shown)
    JkMount /test* testTomcat
    JkMount /* rootTomcat

And this all works great. I also have SSL setup and running for https connections using a similar VirtualHost tag;

<VirtualHost _default_:443>
    JkMount /demo* demoTomcat 
    JkMount /test* testTomcat
    JkMount /* rootTomcat
... SSL Stuff follows ....

What I'm now having trouble is that my SSL Cert is only for www.mydomain.com and NOT mydomain.com.

I've been advised to use the follow mod_rewrite calls;

Options +FollowSymlinks
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [PT,L]

I've placed these before before and after the mod_jk rules in the httpd.conf file. Apache was at first complaining that RewriteEngine was an invalid command, but that went away when I remembered the LoadModule command first :) Now Apache restarts just fine, the server starts and accepts requests and everything works the way it use to ... but thats just it, these mod_rewrite commands appear to have no effect?

I type http://mydomain.com into the browser and I just get my website as per normal. The url does not appear to change to http://www.mydomain.com and when I start to access the secured areas I get warnings that mydomain.com is NOT secured and is serving me a cert from some other website called www.mydomain.com (why this is an issue at all and it can't just use some logic to realise its the same site, I don't know!).

Am I placing the mod_rewrite rules in the wrong place? I've read that it should work, the rewrites should change the url to www. and then pass through to the mod_jk stuff for anything further?

  • What does the rewrite log look like?
    – TheLQ
    Commented Mar 23, 2011 at 1:43
  • Well thats just it, I can't see a rewrite log anywhere? Shouldn't it be in httpd/logs if it was anywhere?
    – Nick Foote
    Commented Mar 23, 2011 at 10:46
  • You have to enable it since a rewrite log in production would be huge. See here: httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
    – TheLQ
    Commented Mar 23, 2011 at 22:20
  • Its empty. I've enabled it and the file gets created. I've set the LogLevel to 9 ... nothing at all is logged into it, the rules aren't firing at ALL, not even to say "I dont know what to do!?"
    – Nick Foote
    Commented Mar 25, 2011 at 10:12

1 Answer 1


I faced a similar issue using mod_rewrite and mod_proxy. https://serverfault.com/questions/296159/need-to-redirect-to-static-url-based-off-of-string-patter-match-in-uri

The problem is that you are bypassing .htaccess file with your proxy rule. Meaning if you place your file in your web root it will not be seen since you are proxying / to rootTomcat and not your apache doc root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.