• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1432
  • Last Modified:

Apache / mod_jk Tomcat and the requesting URL (rewritten)

I have apache 2.0.? and Tomcat 5.5.? both running well.  I am running multiple virtual hosts in Windows server 2003.  

If I request my new JSP based homepage www.servername.com/home I get (correctly) shifted through the mod_jk connector and
deposited in the correct "home" context in Tomcat.  Everything works fine.

My goal is to be able to request www.servername.com and have the request directed to www.servername.com/home .  At least for the initial page.  I want to avoid having the user type the URL correctly.  I would also rather avoid putting an HTML redirect in the way.

I've been told that I can use rewritting.  I've enabled the mod_rewrite.so and tried many different options.  I can never get the silly thing to work exactly as I'd like.

Also, no matter what I put in the mod_jk and rewritelog commands, I get empty log files.  I know I could debug this thing if I could just see what's going on in the rewrite.

Here is the VH that I am attempting to use.  Please bear in mind that this is the 100th different try I've made.

<VirtualHost *>
    ServerName www.orcastech.com
      rewriteengine on
      rewriterule ^.servername.com(.*) www.servername.com/home/$1
        JkMount /home*       worker1
      JkMount /emba48wiki*       worker1
      JkMount /admin             worker1
      JkMount /manager       worker1
      JkMount /*             worker1
      DocumentRoot "c:\Apache\Tomcat\webapps\home"
</VirtualHost>

Hope help is appreciated n advance.

Geoff
0
GeoffWiggs
Asked:
GeoffWiggs
  • 3
1 Solution
 
caterham_wwwCommented:
RewriteCond %{REQUEST_FILENAME} !-f
<VirtualHost *>
    ServerName www.orcastech.com
     RewriteEngine on
     RewriteRule  !^/home - [C]
     RewriteRule ^/(.*) http://www.servername.com/home/$1 [R=301,L]

     JkMount /home*      worker1
     JkMount /emba48wiki*      worker1
     JkMount /admin           worker1
     JkMount /manager      worker1
     JkMount /*           worker1
     DocumentRoot "c:\Apache\Tomcat\webapps\home"
</VirtualHost>

If your rewritelog is empty, the rewriteRule might not be seen, i.e. the <Virtualhost> was not "executed". Did you enable
NameVirtualhost *
a few lines above <Virtualhost>?
0
 
caterham_wwwCommented:
ignore the 1st line,  RewriteCond %{REQUEST_FILENAME} !-f, it's from the clipboard...
0
 
GeoffWiggsAuthor Commented:
You Rock!  I worked on that until midnight last night.  Can you please explain exactly what's happening in these two lines?

    RewriteRule  !^/home - [C]
    RewriteRule ^/(.*) http://www.servername.com/home/$1 [R=301,L]

I'd like to know for the next seriously twisted use of Apache I come up with.

Thanks,
Geoff
0
 
caterham_wwwCommented:
sure.
The 1st line checks, if the path does not start with /home and chains it with the rule below (the hyphen means 'do nothing'/no substitution - in other words: the 2nd rule is only executed, if the path does not start with /home (prevents redirection looping). The 2nd rule will force an external redirect for /everything to /home/everything with the statuscode 301 (moved permanently). L = last rule, no rules below are being processed.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now