To redirect all traffic to Https just add this line in your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Where the domain.com.br is your website URL, this is the fastest way I know how.
To do only redirect with www for www-free add these lines into your .htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.google.com$
RewriteRule (.*) http://google.com/$1 [R=301,L]
</IfModule>
To redirect from without www towards www add these lines into your .htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^dominio.com
RewriteRule ^ https://www.dominio.com%{REQUEST_URI} [L,R=301]
</IfModule>
Trade the.com domain for your domain,
OBS: remember to exchange the https for http if the site does not have ssl
In case I know for example, if I wanted to redirect the whole site to https and without www would be:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www.dominio.com.br$
RewriteRule (.*) https://dominio.com.br/$1 [R=301,L]
</IfModule>
I redirect to https, and after that I remove www. from your dominio.com.br
, reminding you to switch to your domain in question.
I ended up finding a site very practical: https://www.aleydasolis.com/htaccess-redirects-generator/https-vs-http/ just select what and generate.
But that doesn’t check whether this with or without www
– Tiago
For redirect pair with www and one form and for without www and another I will update with both options;
– Bulfaitelo