-1

I have an domain example.com running on an Apache Server and I want to redirect every call to https://example.com to https://sub.example.com.

I have a Virtual Host configured like this:

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

<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]

        ServerName sub.example.com
        ServerAdmin gnarf
        DocumentRoot /var/www/subfolder
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        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
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>
        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
        </Directory>
</VirtualHost>
</IfModule>

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?

Thanks,

Ira

Edit:

To make my problem more clear.. The Reloading error ist not my real problem, it was just to clarify my tries so far ;)

http://example.com <- shows /var/www content = OK
https://sub.example.com <- shows /var/www/sub content = OK
https://example.com <- also shows /var/www/sub content = Not OK, I want this rewritten to https://sub1.example.com

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

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Iralution
  • 103
  • 3
  • 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 01:50

1 Answers1

0

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} ^domain.com
RewriteRule ^(.*)$ https://cloud.%{HTTP_HOST}$1 [R=301,L]
krisFR
  • 12,830
  • 3
  • 31
  • 40