This post describes how to enforce a secure https connection using the .htaccess-file in Apache. At the same time we would like to redirect all www-requests to a non-www secure request. This post is a concatenation of the following forum posts here and here. Edit .htaccess
with the following content.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Now requests to http://www.mydoamin.com, http://mydomain.com and https://www.mydomain.com will be redirected to https://mydomain.com.