SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Kyiv/Ukraine
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Apache's mod_rewrite, VirtualHost and Tomcat5 (jk2): how to get them working together

    Would apache guru help me with a problem.
    I've been trying to make two virtual hosts within Apache 2 and Tomcat 5 integrated by jk2.
    The point is that I need in seperate access log for every site. I also need to have an access through the IP of the server and context of the web application therefore I can't use VirtualHost of Tomcat (described in server.xml).
    I've decided to use mod_rewrite in order to append a context path for the web application. Tomcat would distinguish the both apps according to context. But it doesn't work.
    It seems apache's VirtualHosts don't work in conjunction with mod_rewrite and mod_jk2 though every pair of them works apart from the third.
    The rewrite statements in the apache config shown below don't rewrite URL until VirtualHosts are removed. The other options of RewriteRule give even worse result.
    If I place RewriteRule inside <VirtualHost *> environment the first rule will work. The second woun't.

    Has anybody ecountered with the similar task? If so would you share your experience.
    Thanks in advance.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.host1\.com$ [NC]
    RewriteRule (.*) /host1$1 [PT]
    RewriteCond %{HTTP_HOST} ^www\.host2\.com$ [NC]
    RewriteRule (.*) /host2$1 [PT]

    <VirtualHost *>
    ServerName www.host1.com
    DocumentRoot "/var/www/html/host1"
    ErrorLog /var/log/httpd/error1.log
    CustomLog /var/log/httpd/access1.log common
    <Location "/host1">
    </Location>
    <Location "/host1/*">
    </Location>
    </VirtualHost>

    <VirtualHost *>
    ServerName www.host2.com
    DocumentRoot "/var/www/html/host2"
    ErrorLog /var/log/httpd/error2.log
    CustomLog /var/log/httpd/access2.log common
    <Location "/host2">
    </Location>
    <Location "/host2/*">
    </Location>
    </VirtualHost>

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    when you use virtual hosts you can put mod_rewrite inside a directory block or inside a virtualhost block.
    If you put mod_rewrite outside those blocks the rules *won't be parsed*.
    That's happen when you use virtual hosts.

    I'm not sure what you are going to do,
    could you give to me an example ?

    By the way you need to split the two rules you wrote:

    Code:
    <VirtualHost *>
    ServerName www.host1.com
    DocumentRoot "/var/www/html/host1"
    ErrorLog /var/log/httpd/error1.log
    CustomLog /var/log/httpd/access1.log common
    
    RewriteEngine on
    RewriteRule ^(.*)$ /host1$1 [PT]
    
    <Location "/host1">
    </Location>
    <Location "/host1/*">
    </Location>
    </VirtualHost>
    
    <VirtualHost *>
    ServerName www.host2.com
    DocumentRoot "/var/www/html/host2"
    ErrorLog /var/log/httpd/error2.log
    CustomLog /var/log/httpd/access2.log common
    
    RewriteEngine on
    RewriteRule ^(.*)$ /host2$1 [PT]
    
    <Location "/host2">
    </Location>
    <Location "/host2/*">
    </Location>
    </VirtualHost>
    p.s.
    /host2
    means host2 under root...


    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •