0

I've got a question about apache2 and Virtualhosts.

I declared some in my /apache2/sites-available/ownsites in order to get access via different domains and subdomains, for example:

<VirtualHost *:80>
    ServerName www.domain1.de
    ServerAlias domain1.de
    DocumentRoot /var/www/domain1/
    ServerAdmin myemailaddress.de
    <Directory />
            Order deny,allow
            deny from all
    </Directory>
    <Directory /var/www/domain1>
            Options -Indexes -FollowSymLinks
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName www.domain2.de
    ServerAlias domain2.de
    DocumentRoot /var/www/domain1/
    ServerAdmin myemailaddress.de
    <Directory />
            Order deny,allow
            deny from all
    </Directory>
    <Directory /var/www/domain2>
            Options -Indexes -FollowSymLinks
            AllowOverride all
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

everything works fine, I can access to the different domains and subdomains. But the I enable ssl in order to get secure access to my mail-webaccess

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/apache2/certs/zarafa-ssl.crt
    SSLCertificateKeyFile /etc/apache2/certs/zarafa-ssl.key

    ServerName www.webaccess.domain1.de
    ServerAlias webaccess.domain1.de
    DocumentRoot /path/to/zarafa-webaccess/
    ServerAdmin myemailaddress.de 

    #rewrite rule for https  access
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule (.*) https://webaccess.domain1.de [R]


    <Directory />
            Order deny,allow
            deny from all
    </Directory>
    <Directory /path/to/zarafa-webaccess/>

            Options -Indexes -FollowSymLinks
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>


</VirtualHost>

Also this access works fine, including the rewrite, if I try to access only with http

But the incomprehensible thing is, that now if I try to access to my main domain with https: https://www.domain1.de , I am redirected to the apache2-standard-index.html "It work's", even if I delete it. Further my other domain www.domain2.de is redirected to my first domain, if I try to access with https: https://www.domain2.de -> http://domain1.de

Maybe is there any other file from apache2 exits where former RewriteRules are saved, when I tried some RewriteRules out?

If I declare other rules in order to define an other behaviour, there is no difference.

Does anybody had the same problem or has an idea how to solve it?

1 Answer 1

0

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

HTTPS

Will contain the text "on" if the connection is using SSL/TLS, or "off" otherwise. (This variable can be safely used regardless of whether or not mod_ssl is loaded).

Basically, if the connection is not using HTTPS the URL is statically rewritten to https://webaccess.domain1.de. Requesting http://webaccess.domain1.de/dir/file.txt? Nope, request rewritten to https://webaccess.domain1.de.

But this is a stupid rule to have since the VHost it occurs in is locked to port 443, so it will never be hit by a connection that is not HTTPS. Take this config out of the *:443 config and put it in the relevant *:80 config file.

Better yet, refer to this and use this:

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

Need to find other rule definitions? Look for .htaccess files.

find /path/to/zarafa-webaccess/ -name '.htaccess'
1
  • yeah you were right, there the rewrite rule makes no sense. I put it in the *:80 file and defined every *:80 rule same as *:443 rule with rewrite to http: and now it works
    – Sven Jung
    Dec 28, 2012 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .