Mobile app version of vmapp.org
Login or Join
Looi9037786

: Mod_rewrite with Apache -> mod_jk -> tomcat 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.

@Looi9037786

Posted in: #Apache #Htaccess #ModRewrite #Tomcat #Virtualhost

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;
mydomain.com/demo -> tomcat:8101 mydomain.com/test -> tomcat:8102 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
</VirtualHost>


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 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 ^ 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 mydomain.com into the browser and I just get my website as per normal. The url does not appear to change to 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 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 and then pass through to the mod_jk stuff for anything further?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Looi9037786

1 Comments

Sorted by latest first Latest Oldest Best

 

@Nimeshi995

I faced a similar issue using mod_rewrite and mod_proxy. 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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme