Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an domain running on an Apache Server and I want to redirect every call to to

I have a Virtual Host configured like this:

<VirtualHost _default_:80>
        RewriteEngine On
        RewriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^https://%{HTTP_HOST}/$1
        RewriteRule ^(.*)$ https://cloud.%{HTTP_HOST}/$1 [R=301,L]

        ServerAdmin gnarf
        DocumentRoot /var/www/subfolder
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
        SSLEngine on
        SSLCertificateFile    /etc/apache2/ssl/ssl.pem
        SSLCertificateKeyFile /etc/apache2/ssl/ssl.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
        BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
        <Directory /var/www/subfolder>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
                Satisfy Any

I tried to add the rewrite conditions into the default-ssl file, but when I reload the configuration this error occurs:

Reloading web server config apache2                                                                             
[Sat Mar 22 22:57:11 2014] [warn] _default_ VirtualHost overlap on port 443, the first has precedence

So I removed the default-ssl. How do I get apache to take my rewrite conditions?




To make my problem more clear.. The Reloading error ist not my real problem, it was just to clarify my tries so far ;) <- shows /var/www content = OK <- shows /var/www/sub content = OK <- also shows /var/www/sub content = Not OK, I want this rewritten to

But I don't know how and where to write this rule.

share|improve this question

marked as duplicate by Mathias R. Jessen, dawud, Ward, Jenny D, Scott Pack Mar 23 '14 at 16:11

This question was marked as an exact duplicate of an existing question.

The overlap surely can't be cause by adding a Rewrite line in your configuration, you're not giving ALL of your configuration so we can't see the overlap. Give output of apache2ctl -S – ETL Mar 22 '14 at 22:53
I tried to make my point a bit more clear. See edit part. – Iralution Mar 22 '14 at 23:39
Give output of apache2ctl -S – ETL Mar 23 '14 at 1:50
up vote 0 down vote accepted

My guess is that your RewriteCond is not matched because :

  • Seems that RewriteCond does not like to compare %{HTTP_HOST} against %{HTTP_HOST}

  • %{HTTP_HOST} variable only contains the host (Host Header), without prefix https://

You should try :

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule ^(.*)$ https://cloud.%{HTTP_HOST}$1 [R=301,L]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.