.htaccess simple request to redirect to https:// and www.

I would like to ask what .htaccess redirect to URL https://www. do you recommend. I am looking for a simple solution, with one redirect request.
30 May 2019 at 05:27 PM
0pnshow more
zeddzedd
Hi,

In case of more websites, I have the best experience with this solution:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


The first condition checks, if www. is included in URL. When www. is not present, it will redirect to https://www.

The second rule should be applied, if www. is included, but URL does not start with https://.

31 May 2019 at 09:48 AM
0pnshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2022 AnswerTabsTermsContact us