I have one application with is server over a number of domains (each customizes the appearance of the application.
In addition, there is a common domain which has multiple subdomains to display the same data as above.
So - www.apples.com
appears the same as apples.efruit.co.uk
and - www.bananas.co.uk
appears the same as bananas.efruit.co.uk
etc
Now, I have a wildcard ssl for the efruit.co.uk domain so I want to use the htaccess file to force all efruit.co.uk requests to use https (if not already doing so).
All other domains will not have an ssl so they will need to use http to avoid browser warnings - again from the htaccess file.
I would also like to use the htaccess file so that if someone types www.apples.efruit.co.uk it rewrites as apples.efruit.co.uk (over https as above). However, www. is fine if it's not an efruit.co.uk domain.
Finally, I then have the standard and well documented rewrite rule for codeigniter to make the url prettier.
Here's what I have so far.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(health_check\.php)$
RewriteCond %{HTTP_HOST} ^(.*)\.efruit\.co\.uk
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} !^(.*)\.efruit\.co\.uk
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^www\.([^\.]*)\.efruit\.co\.uk$
RewriteRule (.*) https://%1.efruit.co.uk$1 [R,L]
# block hidden directories
RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
The only bit that seems to work though is forcing efruit.co.uk domains to be served over https.