Redirect http to https
In order to redirect http to https in Apache it's enough to add these lines to .htaccess file in the web root:
RewriteEngine On RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
To redirect www http to non-www https, add these lines to .htaccess:
RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Please note that for these directives to work Apache conf file should contain allowing rules for the web directory:
<Directory /> Options FollowSymLinks AllowOverride All </Directory>
If you have nginx, then you can edit http section of main.conf file:
server { listen 80; server_name www.domain.com domain.com; rewrite (.+) https://domain.com$1 permanent; }