.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.
give a positive ratinggive a negative rating
30 May 2019 at 05:27 PM

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://.

give a positive ratinggive a negative rating
31 May 2019 at 09:48 AM
Share on FacebookShare on TwitterShare on LinkedInSend email
2024 AnswerTabsTermsContact us