Results 1 to 2 of 2

Thread: Apache 2.4 rewrite rules..expert help needed :)

  1. #1

    Default Apache 2.4 rewrite rules..expert help needed :)

    Hi all,
    Have been wrestling with Kolab3 setup recently... well, with apache configuration mostly. i am running Kolab 3.3 on centos7 server with apache 2.4 and Kolab comes with apache configurations that are too general for my taste. Those configuration file were not created for multidomain hosts (vhost environments), but rather for dedicated server setup.
    Biggest problem i have is to create virtualhost configuration for rouncube part of Kolab suit.
    This is default config that ships with rpm:
    Code:
    Alias /roundcubemail /usr/share/roundcubemail/public_html/
    Alias /webmail /usr/share/roundcubemail/public_html/
    <ifModule mod_rewrite.c>
        RewriteEngine On
        # support for CSFR
        RewriteRule ^/roundcubemail/[a-f0-9]{16}/(.*) /roundcubemail/$1 [PT,L]
        RewriteRule ^/webmail/[a-f0-9]{16}/(.*) /webmail/$1 [PT,L]
        # Be compatible with older packages and installed plugins.
        RewriteCond %{REQUEST_URI} ^/(roundcubemail|webmail)/(assets/.*)
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-f
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-d
        RewriteRule ^/(roundcubemail|webmail)/assets/(.*)$ /roundcubemail/$2 [PT,L]
    </ifModule>
    <Directory "/usr/share/roundcubemail/public_html">
        Options +FollowSymLinks
        AllowOverride None
        <ifModule mod_authz_core.c>
            Require all granted
        </ifModule>
    </Directory>
    As you can see it has rewrite rules to accommodate session security token and to get some "older" data, which i didn't understood why they call it older, because all logos and skin icons are not under "new" dir structure, but still under "old"... but anyhow....
    What i am trying to accomplish is instead of having aliases i want to get to my mail on dedicated (sub)domain - sub.example.com and not example.com/webmail or sub.example.com/webmail.
    So this is what i came up with, which is not working, as you might have guessed :
    Code:
    <VirtualHost *:443>
    ServerName sub.example.com
    DocumentRoot /usr/share/roundcubemail/public_html/
    <ifModule mod_rewrite.c>
        RewriteEngine On
        # support for CSFR
        RewriteRule ^/[a-f0-9]{16}/(.*) /$1 [PT,L]
        # Be compatible with older packages and installed plugins.
        RewriteCond %{REQUEST_URI} ^/(assets/.*)
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-f
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-d
        RewriteRule ^/(.*)$ /roundcubemail/$2 [PT,L]
    </ifModule>
    <Directory "/usr/share/roundcubemail/public_html">
        Options +FollowSymLinks
        AllowOverride None
        <ifModule mod_authz_core.c>
            Require all granted
        </ifModule>
    </Directory>
    ## SSL block ##
    bla bla
    ## END SSL##
    </VirtualHost>
    And i have tried to add rewritebase expression hoping it would change things:
    Code:
    <VirtualHost *:443>
    ServerName sub.example.com
    DocumentRoot /usr/share/roundcubemail/public_html/
    <Directory "/usr/share/roundcubemail/public_html">
    <ifModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /usr/share/roundcubemail/public_html/
        # support for CSFR
        RewriteRule ^/[a-f0-9]{16}/(.*) /$1 [PT,L]
        # Be compatible with older packages and installed plugins.
        RewriteCond %{REQUEST_URI} ^/(assets/.*)
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-f
        RewriteCond /usr/share/roundcubemail/public_html/%2 !-d
        RewriteRule ^/(.*)$ /roundcubemail/$2 [PT,L]
    </ifModule>
        Options +FollowSymLinks
        AllowOverride None
        <ifModule mod_authz_core.c>
            Require all granted
        </ifModule>
    </Directory>
    ## SSL block ##
    bla bla
    ## END SSL##
    </VirtualHost>
    What i have found in logs:
    When i leave everything as is (default aliases) and visit site on sub.example.com/roundcubemail everything is working and i see this (just a snippet):
    Code:
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/addcontact.png HTTP/1.1" 200 271
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/filetypes.png HTTP/1.1" 200 9018
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/listicons.png HTTP/1.1" 200 13514
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/messages.png HTTP/1.1" 200 1736
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/messages_dark.png HTTP/1.1" 200 1779
    ip - - [17/Nov/2014:14:26:46 +0100] "GET /roundcubemail/assets/skins/larry/images/quota.png HTTP/1.1" 200 3622
    ip - - [17/Nov/2014:14:26:47 +0100] "GET /roundcubemail/assets/skins/larry/images/selector.png HTTP/1.1" 200 181
    ip - - [17/Nov/2014:14:26:47 +0100] "GET /roundcubemail/assets/skins/larry/images/splitter.png HTTP/1.1" 200 136
    ip - - [17/Nov/2014:14:26:47 +0100] "GET /roundcubemail/assets/skins/larry/images/watermark.jpg HTTP/1.1" 200
    And wen i go to the same page but through "webmail" alias - sub.example.com/webmail :
    Code:
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/addcontact.png HTTP/1.1" 200 271
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/filetypes.png HTTP/1.1" 200 9018
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/listicons.png HTTP/1.1" 200 13514
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/messages.png HTTP/1.1" 200 1736
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/messages_dark.png HTTP/1.1" 200 1779
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/quota.png HTTP/1.1" 200 3622
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/selector.png HTTP/1.1" 200 181
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/splitter.png HTTP/1.1" 200 136
    ip - - [17/Nov/2014:14:29:18 +0100] "GET /webmail/assets/skins/larry/images/watermark.jpg HTTP/1.1" 200 5000
    Exactly the same output except rouncubemail or webmail before assets directory.
    Those files (images/icons) can be found in:
    Code:
    /usr/share/roundcubemail/skins/larry/images/
    Following directory
    Code:
    /usr/share/roundcubemail/public_html/assets/skins/larry/
    contains only css files, so basically with my configuration i get 404 on every image that should be loaded into the site (same log but 404 instead of lovely 200).
    So question is how can i set up rewrite rules so everything is working relative to root domain instead of alias.
    Your help would be greatly appreciated.

  2. #2

    Default Re: Apache 2.4 rewrite rules..expert help needed :)

    Started really trying to understand how rewrite rules work... came up with this:
    Code:
    <Directory "/usr/share/roundcubemail/public_html">
    <ifModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /roundcubemail/
        # support for CSFR
        RewriteRule ^/[a-f0-9]{16}/(.*) /$1 [PT,L]
        # Be compatible with older packages and installed plugins.
        RewriteCond %{REQUEST_URI} ^/(assets/.*)
        RewriteCond %{DOCUMENT_ROOT}/%2 !-f
        RewriteCond %{DOCUMENT_ROOT}/%2 !-d
        RewriteRule ^/assets/(.*)$ /roundcubemail/$2 [PT,L]
    </ifModule>
        Options +FollowSymLinks
        AllowOverride None
        <ifModule mod_authz_core.c>
            Require all granted
        </ifModule>
    </Directory>
    Was really confident it would work..... sooo disappointed in myself right now...

Tags for this Thread

Posting Permissions

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