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.