Apache rewrite rules and DNS settings for HTTPS sites

Solution 1:

As some more assistance for item 3, and maybe 2 as well, how about using Server Name Indication to use two certs on the same host. (ie: www.domain.com and domain.com) Apache's Wiki has some info on the specifics.

--Christopher Karel

Solution 2:

Followup to James's Answer:

RewriteCond %{HTTP_HOST} !^www.domain.com$    [OR]
RewriteCond %{HTTP_PORT} !^443$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

This still doesn't fix #3, you'd need a wildcard or UCC cert for that.

Solution 3:

I think the easiest option is to use mod_rewrite in an htaccess file or right in your httpd.conf. Here is what I use to forward the first two that you need:

RewriteCond %{SERVER_PORT} 80
ReWriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

So, to forward https://domain.com to https://www.domain.com, you could do:

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]

I'm sure there is a way to consolidate those two rule sets if you want to try. Not around my apache server at the moment to test it.