I'd like to do the following: using Apache, redirect all of the following URLs:
http://example.com
http://www.example.com
http://beta.example.com
https://example.com
https://www.example.com
https://beta.example.com
to the same place: https://beta.example.com. I'm close, but not quite there. Here's what I've got:
NameVirtualHost xxx.xxx.xxx.xxx:80
NameVirtualHost xxx.xxx.xxx.xxx:443
### rewrite scheme via http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example
CustomLog /var/log/httpd/example-log combined
ErrorLog /var/log/httpd/example-log
</VirtualHost>
<Directory /var/www/html/example>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://beta.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php
</Directory>
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName beta.example.com
DocumentRoot /var/www/html/example-beta
CustomLog /var/log/httpd/example-beta-log combined
ErrorLog /var/log/httpd/example-beta-log
<IfModule mod_rewrite.c>
RewriteEngine on
# redirect all http -> https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:443>
ServerName beta.example.com
DocumentRoot /var/www/html/example-beta
ErrorLog /var/log/httpd/example-beta-log
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{SSL_PROTOCOL}x %{SSL_CIPHER}x" combined_ssl
CustomLog /var/log/httpd/example-beta-log combined_ssl
SSLEngine on
### SSL details omitted for clarity.
</VirtualHost>
What I get from this:
http://example.com => https://beta.example.com
http://www.example.com => Content for www.example.com (/var/www/html/example)
http://beta.example.com => https://beta.example.com
https://example.com => https://example.com (correct content but wrong url)
https://www.example.com => https://www.example.com (correct content but wrong url)
https://beta.example.com => https://beta.example.com
It's probably worth noting that my ssl certificate is fully wildcard-able, so I should be good there, and all the SSL stuff seems to be working (even when the pages are being served up under https://example.com). Meanwhile, there are no .htaccess files in place -- I'm trying to do everything through apache config.
So the problem is getting https://example.com to redirect correctly, with and without the www prefix. Any advice out there? Thanks!
ServerAlias www. example.com
an error in pasting?